A Survival Guide To Install rlang From GitHub On Windows

rlang
Windows
Author

Hiroaki Yutani

Published

January 25, 2019

I don’t have any strong feelings about OSs. They are just tools. I had been a Mac user for 10+ years since I was 10, and now I’m using Windows for no reason. All OSs have their pros and cons. For example, I like Mac, but, in the late 90s, I was very disappointed at Mac because it didn’t have fonts to display Shift_JIS art nicely.

Anyway, I’m using Windows and I need to survive. Here’s an error I often see when I try to install rlang package from GitHub by devtools::install_github():

installing to C:/path/to/R/win-library/3.5/rlang/libs/x64
Error in file.copy(files, dest, overwrite = TRUE) : 
  (converted from warning) problem copying .\rlang.dll to
C:\path\to\R\win-library\3.5\rlang\libs\x64\rlang.dll: Permission denied

This is because rlang.dll is used by the current R session (or other session?), so Windows won’t let me overwrite it. What should I do? Here’s some advice.

Restart the R session

This is always necessary. Since rlang is very fundamental package, it might be loaded as a dependency of some attached or loaded package (if you are curious about the differences between load and attach, R Packages helps). You need a fresh session with no packages (except for base packages) loaded. On RStudio, Ctrl+Shift+F10, or “Restart R” in “Session” menu.

For usual packages, this is enough. But, rlang is not the case…

Use remotes::install_github() instead of devtools

devtools::install_github() is just re-exported from remotes package. So, are the same one. But, if I use devtools::, devtools’s dependencies are loaded, and, at the moment, rlang is included here. So, the same error will occur.

On the other hand, remotes:: doesn’t need rlang directly or indirectly. So, run

remotes::install_github("r-lib/rlang")

(You might also need remotes::install_github() for other dependency packages like glue.)

Note that, pkg package seems aware of this kind of problems, so we’ll be free from this kind of problems when pkg is mature!

Extra steps?

Usually, restarting the session + using remotes::install_github() works. But, in the past, I needed some extra steps. I don’t know why, but it seemed RStudio loads rlang in background (c.f. https://github.com/r-lib/remotes/issues/131). So, for future references, I note some. Hope this will never be needed again…

Remove rlang

Removing package might help, since removed package cannot be loaded.

remove.packages("rlang")

Use git clone, R CMD build and R CMD INSTALL

If you really need to be away from RStudio, or even from any R sessions. In those cases, you can use git and R CMD build and R CMD INSTALL on console.

git clone https://github.com/r-lib/rlang
R.exe CMD build --no-manual --no-build-vignettes rlang/
R.exe CMD INSTALL [--some-options-i-dont-remember] rlang_*.tar.gz