72

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

0

1 Answer 1

97

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.

6
  • 13
    Nice. Should probably also check "~/.Rprofile" (or, more formally, file.path(Sys.getenv("HOME"), ".Rprofile"), since it's searched as well. Jan 26, 2016 at 3:57
  • Very detailed steps, Thank you, I guess the search order is 1.the current directory. 2.the home of R(or where ~ points to) 3 the place you install R/etc Feb 7, 2018 at 6:45
  • What is meant by "getwd() will return the current directory at startup"? Is the current directory that which I see when I click the Terminal tab and type $ pwd ?
    – Wassadamo
    Aug 7, 2019 at 23:40
  • Your suggestion didn't work, but @JoshO'Brien 's comment works. Do you understand that?
    – Christoph
    May 18, 2020 at 10:57
  • @Wassadamo kinda late to the party but getwd() returns your current working directory which tipically ends up being where the directory on which you started R so lets say your in /micron/ and you type R in terminal executing the binary in path if you do getwd() it will return /root/
    – Imeguras
    Oct 8, 2021 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.