1

Inspired by Miles McBain's drake video, I want to install the fnmate package/RStudio add-in. But remotes::install_github insists that I don't have magrittr, when in fact I do.

I use a site library configured in an environment variable, and, to try to make it easy to find I installed magrittr in both my site library and my normal library.

### Confirming library locations
Sys.getenv("R_LIBS_SITE")
# [1] "C:\\rlib"

.libPaths()
# [1] "C:/rlib"                            "C:/Program Files/R/R-4.0.2/library"

### Confirming `magrittr` is installed
packs = installed.packages()
packs[packs[, "Package"] == "hrbrthemes", c(1, 2, 3)]
#          Package    LibPath                              Version
# magrittr "magrittr" "C:/rlib"                            "1.5"  
# magrittr "magrittr" "C:/Program Files/R/R-4.0.2/library" "1.5"  


### Attempting to install `fnmate`
remotes::install_github("MilesMcBain/fnmate")
# Downloading GitHub repo MilesMcBain/fnmate@HEAD
# √  checking for file 'C:\Users\grego\AppData\Local\Temp\RtmpIx8abP\remotes22d49002b1a\MilesMcBain-fnmate-908f638/DESCRIPTION' ...
# -  preparing 'fnmate':
# √  checking DESCRIPTION meta-information ... 
# -  checking for LF line-endings in source and make files and shell scripts
# -  checking for empty or unneeded directories
# -  building 'fnmate_0.0.1.9000.tar.gz'
#    
# * installing *source* package 'fnmate' ...
# ** using staged installation
# ** R
# ** inst
# ** byte-compile and prepare package for lazy loading
# Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
#   there is no package called 'magrittr'                                                 ##### <<<- see error!
# Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
# Execution halted
# ERROR: lazy loading failed for package 'fnmate'
# * removing 'C:/Program Files/R/R-4.0.2/library/fnmate'
# Error: Failed to install 'fnmate' from GitHub:
#   (converted from warning) installation of package ‘C:/Users/grego/AppData/Local/Temp/RtmpIx8abP/file22d45afbf9f/fnmate_0.0.1.9000.tar.gz’ had non-zero exit status

The issue is not unique to these packages. I next attempted to install "hrbrmstr/hrbrthemes" and it errored because it couldn't find extrafont, which is also installed.

All of this is done in a fresh R session in RStudio.

Oddly, the problems seem worse in the built-in RGui or R.exe - I almost never run R this way, but it seems unaware of either of my libraries:

### In RGui
### The environment variable is present, but the lib paths are not updated
> Sys.getenv("R_LIBS_SITE")
[1] "C:\\rlib"

## This path does not exist on my computer
> .libPaths()
[1] "C:/projects/r-base/src/R-source/library"

## the site library is not checked
> library(magrittr)
Error in library(magrittr) : no library trees found in 'lib.loc'

## works if I manually specify the library
library(magrittr, lib.loc = "C:\\rlib")
Warning message:
package 'magrittr' was built under R version 4.0.3
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294

1 Answers1

1

When I first encountered the problem, I specified the site library only as an environment variable. I attempted to fix by adding the line .Library.site <- "C:/rlib" to my Rprofile.site file, but nothing changed - including the behavior of RGui and R.exe. I was surprised and confused that they don't seem to recognize my site library.

So I explicitly added the site library to .libPaths() in my Rprofile.site file (located in Program Files/R/R-4.0.2/etc, and that seems to have done the trick. I was then able to use remotes::install_github both from RStudio and from R.exe.

My Rprofile.site file now looks like this:

.Library.site <- "C:/rlib"
.libPaths(.Library.site)
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294