2

I want to change the prompt in R from > to R> and I know I should use the options command options(prompt="...") and it works, but then when I restart R the prompt is back to >.

Is there anyway to save the change so that it sticks?

miken32
  • 42,008
  • 16
  • 111
  • 154
David
  • 21
  • 3

1 Answers1

3

Use .Rprofile file:

You can customize the R environment through a site initialization file or a directory initialization file. R will always source the Rprofile.site file first. On Windows, the file is in the C:\Program Files\R\R-n.n.n\etc directory. You can also place a .Rprofile file in any directory that you are going to run R from or in the user home directory.

At startup, R will source the Rprofile.site file. It will then look for a .Rprofile file to source in the current working directory. If it doesn't find it, it will look for one in the user's home directory. There are two special functions you can place in these files. .First( ) will be run at the start of the R session and .Last( ) will be run at the end of the session.

More details are here

miken32
  • 42,008
  • 16
  • 111
  • 154
Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
  • Thanks for the quick answer. I tried that, to no avail. For many hours, I searched through documentation regarding .Rprofile and tried everything, and the options would never stay. I finally managed to have it work, on OSX, I opened the RStudio package in applications and modified the options.R file I found in there. That worked. If anyone can give me feedback on this approach, I would appreciate it, not sure if what I did was right, even though it worked. – David Feb 04 '16 at 01:08
  • @David Mmm... Just changed my .Rprofile prompt to `options(prompt="QQQ> ", digits=4, show.signif.stars=FALSE)` and typed **R** and prompt was `QQQ>`. Apparently, yours is not read. I have it in my working directory, `C:/Users/XXX/Documents/R/.Rprofile` and it just works – Severin Pappadeux Feb 04 '16 at 03:36
  • @David, aha, I might know why. In Rstudio, Tools->Global Options->General you could set default working directory. So as soon as this directory has .Rprofile, it will be picked up, just checked. Mine set to directory I worte earlier, it has .Rprofile, and all options are picked up – Severin Pappadeux Feb 04 '16 at 03:40
  • Hey thanks for your help! Really I tried to put my .Rprofile file in my working directory and putting the options in there. It just does not seem to work for me. The only way has been to go to Applications/R Studio/Contents/Resources/R/Options.R and modify that file directly. I've haven't read of anyone else who did it this way. – David Feb 05 '16 at 21:12