Asked on superuser and got crickets, so trying here. This one seems to straddle the border of SU/SO.
In troubleshooting some kind of R configuration issue that was causing a pandoc conversion failure when trying to Knit a .Rmd on a colleague's Windows 10 machine, I noticed that the first path in .libPaths()
was pointing to a path on a network directory rather than the c:/Users/[username]/R/win-library/...
directory.
Running Sys.getenv()
in R showed that HOMEDRIVE
and HOMEPATH
were (as expected) c:
and \Users\[username]
, yet there was a HOME
environment variable listed that was pointing to the network path that we'd found in .libPaths()
Running SET
in a cmd shell did not list this HOME
environment variable at all, so it seems to be something that R found somewhere else...
Where does R get this HOME
environment variable?
FWIW: I fixed the config issue by setting a Windows User Environment variable HOME=%HOMEDRIVE%%HOMEPATH%; R then set all the other environment variables appropriately from there.
R startup is somewhat complicated, but it is pretty well documented. The usual starting place is help("Startup")
. The answer to your question is not documented there, but you will find this clue in the See also section:
For the definition of the ‘home’ directory on Windows see the ‘rw-FAQ’ Q2.14. It can be found from a running R by Sys.getenv("R_USER")
and indeed the cited FAQ at https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f gives us the answer:
The home directory is set as follows: If environment variable R_USER is set, its value is used. Otherwise if environment variable HOME is set, its value is used. After those two user-controllable settings, R tries to find system-defined home directories. It first tries to use the Windows "personal" directory (typically C:\Users\username\Documents). If that fails, if both environment variables HOMEDRIVE and HOMEPATH are set (and they normally are), the value is ${HOMEDRIVE}${HOMEPATH}. If all of these fail, the current working directory is used.
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