Locate the ".Rprofile" file generating default options

RRprofile

R Problem Overview


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

R Solutions


Solution 1 - R

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"),
             file.path(Sys.getenv("HOME"), ".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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionh.l.mView Question on Stackoverflow
Solution 1 - RflodelView Answer on Stackoverflow