Tyler Rinker Tyler Rinker - 9 months ago 45
R Question

Change path.expand location (Win 7)





I want it to yield:


The directory for the windows command prompt is
. This indicates that this is my windows home directory.

tells me to look at the rw-FAQ (LINK). This gives information above my cognitive ability. I decided to try to experiment as below:

> Sys.getenv("R_USER")
[1] "C:\\Users\\trinker\\Documents"
> normalizePath("~")
[1] "C:\\Users\\trinker\\Documents"

> Sys.getenv("R_USER") <- "C:\\Users\\trinker"
Error in Sys.getenv("R_USER") <- "C:\\Users\\trinker" :
target of assignment expands to non-language object
> normalizePath("~") <- "C:\\Users\\trinker"
Error in normalizePath("~") <- "C:\\Users\\trinker" :
target of assignment expands to non-language object

I saw:


But got scared I was messing with things I ought not be blindly messing with and decided to ask for guidance.

So again I would like to have
again (this was the default for my last PC) not the
it is now.


To persistently reset the directory that "~" resolves to for all users, put the following in the file Renviron.site, located in $RHOME/etc/Renviron.site:


(If the file is not already there, you can just create it yourself.)

If a computer supports multiple R users, and each wants to set their own R_USER location, each can put the following in their own ".Rprofile" file:

Sys.setenv(R_USER = "C:/Users/trinker")

".Rprofile" is looked for in the user's home directory, which is returned by typing Sys.getenv("HOME"). See ?Startup and the R for Windows FAQ for more details.

(Thanks to @Dason for pointing out the .Rprofile option.)