1

I often run my scripts from an R terminal with source('my_script.r'). I would like be able to use a statement in my scripts that quietly terminate execution of the script anywhere I type it and that returns control to the terminal, where I can inspect my variables.

The answers to this thread suggest using

q()

or

stop()

to stop an R script, but q()exits the session, and stop() throws an exception and is not quiet (especially if I have something like options(error=traceback) activated, since it forces R to print the call stack).

Is there a way to quietly stop execution of the script and return control to the R terminal with a short command?

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • Have you tried `browser()`? – Josh O'Brien Feb 13 '13 at 21:27
  • 1
    [We've been here before.](http://stackoverflow.com/q/14469522/271616) – Joshua Ulrich Feb 13 '13 at 21:28
  • @JoshuaUlrich -- Funny. I hadn't seen that one, but was also just about to edit to mention typing `Q` to exit the browser! – Josh O'Brien Feb 13 '13 at 21:29
  • @JoshO'Brien: it was the first result when I searched for "[r] stop source". – Joshua Ulrich Feb 13 '13 at 21:32
  • Thanks @JoshuaUlrich I didn't see that question either. I think both questions are very similar. I would like to directly return to the original environment, but from I read in the comments, I need to type `Q` to do that (and I imagine I lose my variables doing so), is that the case? – Amelio Vazquez-Reina Feb 13 '13 at 21:39
  • You do realize that the desire to both return to the original, calling environment and also retain access to all variables from inside your scripts/functions is basically contrary to how R works at a fundamental design level, re:scoping? – joran Feb 13 '13 at 23:06

0 Answers0