Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locate the ".Rprofile" file generating default options

Tags:

r

rprofile

In R and RStudio, I think I have messed around with the .Rprofile file a few times, and I currently am loading up an old version of it upon startup of R or RStudio, is there a way that I can quickly find the location of the file that is generating the default options?

Thanks

like image 643
h.l.m Avatar asked Dec 06 '12 01:12

h.l.m


People also ask

Where can I find .rprofile file?

Rprofile is located in the users' home directory ( ~/. Rprofile on MacOS/Linux). This . Rprofile is run whenever you start up R.

Which file contains settings that R uses by default?

When you start R, it will by default source a . Rprofile file if it exists. This allows you to automatically tweak your R settings to meet your everyday needs.

How do I create a .renviron file?

Renviron file in your Home Directory. Find your Home directory by clicking on the Home button in the Files pane of RStudio. Then, simply create a new text file (File > New File > Text File) and save it as . Renviron .


1 Answers

Like @Gsee suggested, ?Startup has all you need. Note that there isn't just the user profile file, but also a site profile file you could have messed with. And that both files can be found in multiple locations.

You could run the following to list existing files on your system among those listed on the page:

candidates <- c( Sys.getenv("R_PROFILE"),                  file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),                  Sys.getenv("R_PROFILE_USER"),                  file.path(getwd(), ".Rprofile") )  Filter(file.exists, candidates) 

Note that it should be run on a fresh session, right after your started R, so that getwd() will return the current directory at startup. There is also the tricky possibility that your profile files do modify the current directory at startup, in which case you would have to start a "no-profile" session (run R --no-site-file --no-init-file) before running the code above.

like image 175
flodel Avatar answered Sep 21 '22 03:09

flodel