问题
The tilde expression is not working on my RStudio! I am using a windows 10 OS.
Update : After looking more carefully(thanks to Dason) It seems the "~" is pointing to "user/Documents/" rather then "user/". is there any work around?
Any help?
回答1:
The home directory in Windows R is set using the environment variable R_USER
Set this using Windows (search from the Start Menu for "environment variable"). Whatever you set this to will become what R uses for ~
. I have mine set to C:\Users\trehman\R
.
Here is how mine looks.
回答2:
As you found out yourself, R's ~
points to your documents folder. An easy way to work around this could be to start the paths you want to reference with ~/../
. So your setwd
call would look like this:
setwd('~/../{your actual path from home}')
The same problem occurs on my Windows PC. I do not have a Linux machine at hand to test whether it is the same there. R gets this variable from the R_USER
environment variable. You can override that in your R environment startup file. This issue is not specific to RStudio and also occurs when you start an R session from the command line.
回答3:
At startup, R looks for Renviron.site
in the R_HOME
directory. Open and edit it
file.edit(file.path(Sys.getenv('R_HOME'), 'etc', 'Renviron.site'))
Define R_USER
in that file with the path you want '~'
to point to:
R_USER = 'C:/Users/USERNAME'
References: R for Enterprise: Understanding R’s Startup
来源:https://stackoverflow.com/questions/34400903/tilde-expression-not-functioning-in-r