6

I'd like to be able to type q() in R and have R quit rather than be prompted as to whether I want to quit.

Is there some code that I could put into my .Rprofile file to make this happen?

I'd prefer if I didn't have to have a custom function floating around in my workspace.

Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
  • 2
    Possible dup: http://stackoverflow.com/questions/4996090/how-to-disable-save-workspace-image-prompt-in-r – Brandon Bertelsen Oct 24 '12 at 04:47
  • 1
    Mac version of R GUI has this option under Preferences > Startup, too. RStudio > Tools > Options > General > Save workspace .Rdata on exit > "Always" but that might not work if you're actually typing quit. – Brandon Bertelsen Oct 24 '12 at 04:54
  • @BrandonBertelsen I agree it is a borderline duplicate. I've modified the question to make it explicit that I'm interested in strategies involving Rprofile. In particular, I like your answer and it was not mentioned on the previous question. – Jeromy Anglim Oct 24 '12 at 06:16
  • That's why I answered, it didn't fit the mold. And you specified "when I type q()". Which is different than the other potential answer. – Brandon Bertelsen Oct 24 '12 at 07:42

2 Answers2

5

In your Rprofile.site file:

q <- function(save = "yes", status = 0, runLast = TRUE){
.Internal(quit(save, status, runLast))
#<environment: namespace:base>
}
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
0

Using R --vanilla works better

LIAR
  • 1
  • 3
    Welcome to Stack Overflow! I'm not sure who you're addressing with this answer; are you commenting on the accepted answer? Or providing some guidance to the original asker? If you're addressing the other answer, this post should be removed as it's not an answer. If you're addressing the question, you should [edit your post](https://stackoverflow.com/posts/60043504/edit) to make it more obvious that you're doing so. – Das_Geek Feb 03 '20 at 16:43