0

When typing interactively, if you realize you've made a mistake and want to break out of the braced expression without executing it, what's the best way to do it?

I usually just do something like this (type random characters), which works. I seem to recall it not working a few times, though. For instance, I'll often type a closed parens ), which doesn't break out of the braced expression if I've already typed an open parens somewhere.

> if(TRUE) {
+ !@##!@#
Error: unexpected '@' in:
"if(TRUE) {
!@"

Or if you've typed a quote then the above doesn't work:

> if(TRUE) {
+ "
+ !@##!@#
+ 

So the question is this:

Without having to evaluate what has been typed on previous lines, how can you break out of the endless sequence of "give me more input" + prompts?

Or stated differently, given,

if(TRUE) {
...
+ 

what expression breaks evaluation for all possible ...'s?

Brian Diggs
  • 57,757
  • 13
  • 166
  • 188
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
  • (I tested in a non-Gui mode and the `esc` does not work but the linked question has an answer for those using a naked-console interface.) – IRTFM Oct 01 '13 at 21:50
  • 1
    Have you tried Ctrl+C? This works for most REPLs I've used. – nneonneo Oct 01 '13 at 21:52
  • ctrl-c does not work in some gui's, but ctrl-c followed by `esc` would be fairly general exit-to-top strategy. – IRTFM Oct 01 '13 at 21:57
  • I'm on a mac, and for me it's `CTRL+C` (not `CMD`) in both the R GUI and in terminal. I also use `RStudio` hosted on an amazon box, and there it is `esc` – Ricardo Saporta Oct 01 '13 at 22:01
  • There is a posting to r-help today that warns people with a Java interface that ctrl-c may abort Java and crash R. – IRTFM Oct 01 '13 at 23:58
  • I'd tried CTRL-C before but never with escape. Thanks. @DWin Noted. Fortunately I don't use a Java-based interface. – Ari B. Friedman Oct 02 '13 at 01:35

0 Answers0