I have a Macintosh and I am trying to automatically load packages, homemade functions, and use modified setting every time I start R. I believe this can be done with a file called Rprofile.site, and by creating the functions .First and .Last in that file.
One problem is, I have no idea what my R_HOME directory is, what it is used for, or if it even exists. I found two functions that I thought both gave me its location but I am getting different results.
Here's the first
> Sys.getenv("R_home")
R_home
""
And the second
> R.home()
[1] "/Library/Frameworks/R.framework/Resources"
As far as I can tell that second directory doesn't even exist on my machine. I am currently running R from my applications directory.
Typically . Rprofile is located in the users' home directory ( ~/. Rprofile on MacOS/Linux).
Renviron file is sourced. Typically . Rprofile is located in the users' home directory ( ~/. Rprofile ), however a different location can be configured by setting the R_PROFILE_USER environment variable.
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.
Over the years I have come to rely on the help(Startup)
documentation as the best place to read up on this. There are numerous per-user and per-site configuration file as is customary for rich applications. It may seem like overkill at first but it is a really good system. And once you grok Renviron
versus Renviron.site
and dito for Rprofile
, you appreciate the consistent behaviour across platforms.
Michael, I too have found this topic to be a bit confusing. I'm on a Mac as well. I created an "Rprofile" file which has all my customizations in it. Here's how mine works (I don't think there is anything special about my set up):
HTH Bryan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With