I am looking to make RStudio quit gracefully whilst in non- interactive mode. I have tried:
stop("",call = quit(save = "no",status = 0, runLast = FALSE))
It works when calling RScript myscript.R
from cmd/shell.
However, when I source the file in RStudio, I get a R session aborted error. Is there anyway to do this from RStudio?
The RStudio application and the R session are different processes (e.g. in Windows, if you open the Task Manager, you can see "RStudio R session" in the list of background processes). When you call q()
interactively, it closes both, but when you source the script it only closes the R session, not the RStudio program, which then returns the error message and offers to create a new session.
There doesn't seem to be a way to close RStudio non-interactively. If there were, it would probably be in the rstudioapi package (https://github.com/rstudio/rstudioapi).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With