Workaround for bad user path


Windows systems with unusual paths

On recent versions of Windows, the path to the userís Documents directory is typically C:/Users/<username>/Documents and R packages are stored in Documents\R\win-library\x.y where "x.y" is the major.minor R version, eg, 3.5. The temporary directory is at C:/Users/<username>/AppData/Local/Temp.

The problem

We have had issues with certain R functions where
   1. the userís area was configured on a network drive, even though the actual location was on the local machine;
   2. the <username> included CJK (Chinese-Japanese-Korean) characters.

After installing R, you can check this by running

tempdir() ; Sys.getenv("R_USER")

If "\\\\" or "//" or non-Western characters or unicode hex values (eg, <U+611B>) appear in the output, some R functions will fail.

These workarounds involve creating directories on the C: drive and then pointing R to use them.

A workaround

Create a new folder on the C: drive, call it "R", then do a sub-directories named R_temp and R_libs, so you have "C:\R\R_temp" and "C:\R\R_libs". (You can use different names, but keep them short and without spaces or symbols.)

You may be able to use the .Renviron or .Rprofile files to point R to these at start up, provided there is no problem with the path to Documents. See ?Startup in R for details of the process. I prefer to set environment variables.

Go to Control Panel > System > Advanced system settings > Environment variables.

Create a new User environment variable named TMPDIR with value C:\R\R_temp. You should already have TEMP and TMP variables: do not change those. R looks first for TMPDIR; if not found, it uses TEMP or TMP. I think it's the only software to use TMPDIR, so setting this won't affect other programs.

For the package libraries, create another environment variable with the name R_LIBS_USER and value C:\R\R_libs\%v.

The next time you run install.packages(), you will see pop-up boxes asking if you want to create a new directory. A new subdirectory, C:\R\R_libs\x.y, will be created, where "x.y" indicate the R version, currently 3.5.  Packages will be installed in the appropriate subdirectory for the version of R being run.


If you have suggestions, comments or questions about installing the software needed for the workshop please email stats.bcss@gmail.com.


Page updated 21 July 2018 by Mike Meredith