I am launching R (an interactive program) in a screen window in a remote session:

ssh me@..
screen -S R_ProjectName

In the R session, I would like to break execution. Normally, this would be via ctrl+c.

However, the command is getting submitted to screen instead of to R. What is the correct way to break in a program inside a screen window?

To clarify, I am not looking to kill the R process. Rather, ctrl+c would be used to manually break out of (eg) a for loop.

I am working in iTerm2 on a Mac OS X connecting to Ubuntu 13.04

  • I've never had a problem using ctrl+C to break an app, even when running within screen (I'm almost always running in screen, or tmux). Are you sure this problem is "screen" related? – Greg Hewgill Oct 28 '13 at 21:09
  • @GregHewgill, truthfully, no I am not sure. What I am sure is that I hit ctrl+c and my R session continues running (evidenced by the file system, etc) but I am no longer actively in that window. – Ricardo Saporta Oct 28 '13 at 21:18
  • That should work: screen receives your Ctrl+C keystroke but passes it to the terminal where R is running. Does it work if you don't run screen? – Gilles Oct 28 '13 at 23:59
  • @Gilles, yep, if I do not run screen (but still ssh to remote), ctrl+c works as normal – Ricardo Saporta Oct 29 '13 at 0:44

To get out of R you typically use the command q() to quit a running instance.


Run R.

$ R

Sitting at an R prompt:

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]


Now exit:

> q()
Save workspace image? [y/n/c]: n

Breaking a running R command

If you've run something in R and want to abort it, Ctrl + C is usually the way to accomplish this. If this doesn't work you might want to try Ctrl + \.

If neither of the above work, you might have luck trying to send a signal to the running R process.

$ kill -USR1 <pid of R>
$ pkill -USR1 R

The 2nd form will kill all the running R processes, but saves you on having to look up the PID.



You can get a process id by running ps -A | grep R and then kill pid.

  • To clarify, I am not looking to kill the process. I am looking to manually break out of, say, a for loop – Ricardo Saporta Oct 28 '13 at 21:15
  • If you break from a for loop in R, does that not also kill the process or is it an interactive shell? – sean_m Oct 28 '13 at 21:17
  • it's interactive. Similar to python – Ricardo Saporta Oct 28 '13 at 21:19
  • I haven't been able to find a good solution. Have you tried tmux? Does most everything screen does but can be a little nicer for interactive shells inside of tmux sessions. Learning curve is a little steep though. – sean_m Oct 28 '13 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.