In Windows 7, I have my .Rprofile in a custom location (not R_HOME
, not HOME
). I informed the OS of this location via the user environment variable R_ENVIRON_USER
pointing to this location. There is no other .Rprofile anywhere else.
In RStudio, I set the default working directory (when not in a project) to this same location
When not in a project, the .Rprofile is properly sourced. However, when inside another project or when creating a new one, the .Rprofile is not sourced.
How do I ensure, that my .RProfile is properly sourced even inside projects (assuming there is no project-specific .RProfile inside the project dir)? I thought the environment variable would take care of that.
I had to set the environment variable R_PROFILE_USER
and provide the full path and filename of the .Rprofile. In a command prompt, I typed:
SETX R_PROFILE_USER "C:\Users\tspeidel\OneDrive\.Rprofile"
You misunderstand what R_ENVIRON_USER
is for; it sets a value to source an (optional) .Renviron
file for the user from the location it provies.
It does not affect what the system thinks your home directory is. That is still governed by HOME
which you set on Windows with the same UI. And you can't just substitute R_HOME
for it.
You can however read very carefully what R tells you about its process in help(Startup)
. Which is, as often, somewhat dense and terse but it does get to the real meat. In short, I think you may want to use another variable to point to alternate Rprofile.
None of this has anything to do with RStudio which, after all, just calls R for you (and cannot, as a running process, alter HOME
).