Is there any way to stop an R program without error?
For example I have a big source, defining several functions and after it there are some calls to the functions. It happens that I edit some function, and want the function definitions to be updated in R environment, but they are not actually called.
I defined a variable justUpdate
and when it is TRUE
want to stop the program just after function definitions.
ReadInput <- function(...) ...
Analyze <- function(...) ...
WriteOutput <- function(...) ...
if (justUpdate)
stop()
# main body
x <- ReadInput()
y <- Analyze(x)
WriteOutput(y)
I have called stop()
function, but the problem is that it prints an error message.
ctrl+c is another option, but I want to stop the source in specific line.
The problem with q()
or quit()
is that it terminates R session, but I would like to have the R session still open.
As @JoshuaUlrich proposed browser()
can be another option, but still not perfect, because the source terminates in a new environment (i.e. the R prompt will change to Browser[1]>
rather than >
). Still we can press Q
to quit it, but I am looking for the straightforward way.
Another option is to use if (! justUpdate) { main body }
but it's clearing the problem, not solving it.
Is there any better option?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…