On (my install of) RStudio on Windows path.expand("~")
returns "C:/Users/myusername/Documents". However RScript -e path.expand('~')
from the command line returns "C:\Users\myusername" (the same from the R REPL). This makes scripts that use a tilde and work in one environment fail in the other. A possible fix is to execute set R_USER=C:\Users\myusername\Documents
before running the script from the command line, but this seems like a kludge; it also might trip up other users of my script unless I warn them to set R_USER
. I also tried adding an entry to ~/.Renviron
but that seemed to cause the 'Source' button in RStudio to fail.
What is the best way to make RStudio and R agree on how to expand tilde?