Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

R_USER #3

Open
jeroen opened this issue Apr 10, 2019 · 1 comment
Open

R_USER #3

jeroen opened this issue Apr 10, 2019 · 1 comment

Comments

@jeroen
Copy link
Member

jeroen commented Apr 10, 2019

Somebody has suggested this on the mailing list:

Suggestion:
Add information about ${environVar} to the R for Windows FAQ, and explain how it may be used in Renviron.site or .Renviron files, in your https://cran.r-project.org/bin/windows/base/rw-FAQ.html web page.

 

Why? It allows a site-wide solution to an R installation challenge.
1.       IT depts. may map the Windows HOME environmental variable to a network drive, so that it will be backed up.

2.       R can be incredibly slow in package installations and library loads when the R_USER is a network drive.

3.       Renviron.site does not run R functions, but is the correct place to set R_USER, so that it will not be set by HOME. So ‘Sys.getenv(“USERNAME”)’ does not work in Renviron.site. Neither does %USERNAME% (the Windows way to call the variable).

4.       An obvious, appropriate R_USER folder in Windows is “C:\Users\(username)\Documents”

A solution is to include this in Renviron.site:

     R_USER=C:\\Users\\${USERNAME}\\Documents

 

An even better solution would be

     R_USER=${USERPROFILE}\\Documents

Except that R removes the back-slashes in USERPROFILE.  USERPROFILE generalizes to more versions of Windows. Some earlier version did not have user files within C:\Users.

 

Details
Our IT Dept. sets our HOME, HOMEDRIVE and HOMEPATH variables to a network drive. So R_USER is set to that drive, and the packages are installed there. The result is that Rstudio installs packages and opens libraries incredibly slowly (minutes, or 10s of minutes). As a result, my group has not wanted to use R.

 

So I wanted to set R_USER within Renviron.site, so all my group would have R_USER mapped to their hard drives, which makes R run quickly.

 

After trying various things, I ended up with a Renviron.site file that looks like this:

# Set the home directory to be a writable, local folder. Among other things, this will house package installations, for quick loading of libraries.

R_USER=C:/Users/${USERNAME}/Documents

 
@mcanouil
Copy link

mcanouil commented Apr 6, 2022

To "fix" REditorSupport/vscode-R#1057, I went to a different road and set the environment variable using Windows + R to run rundll32.exe sysdm.cpl,EditEnvironmentVariables with R_USER / %UserProfile% (key/value).
For system-wide change, admin privileges are required, i.e., run the rundll32.exe as admin in cmd / pwsh / Windows + R.

image

To note, the default value for R_USER is %UserProfile%\Documents.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants