How to disable “Save workspace image?” prompt in R?

前端 未结 11 1871
迷失自我
迷失自我 2020-11-29 23:51

When I exit the interactive R shell, it displays an annoying prompt every time:

>
>
Save workspace image? [y/n/c]: n

I\'m always answering \"no\" to it

11条回答
  •  我在风中等你
    2020-11-30 00:09

    If, like me, typing out a whole pair of brackets seems like too much effort to exit the repl you can try this:

    exit <- structure(list(), class = "exit_command")
    
    print.exit_command <- function(...) {
      q("no")  # exit without saving
    }
    

    This creates a new class, which causes R to exit when attempting to print said class. The upshot being that if you run exit in the R repl, the whole thing will exit (because it tries to print it).

    NB: You can add it to ~/.Rprofile to load at the start of every session.

提交回复
热议问题