Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to non-interactively quit RStudio gracefully

Tags:

r

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?

like image 352
ArunK Avatar asked Jul 04 '16 09:07

ArunK


1 Answers

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).

like image 172
Philippe Marchand Avatar answered Oct 17 '22 11:10

Philippe Marchand