[R] install.packages handles package vs package dependencies differently

Chase Clark cc|@rk42 @end|ng |rom u|c@edu
Mon Sep 9 04:14:57 CEST 2019

First post, please excuse any ignorance.

install.packages() seems to only respect install.packages(lib=) for
the specified package (in the below case {purrr}) and will ignore any
dependencies ({magrittr}, {rlang}) if they are found in any of the
directories in .libPaths() (e.g. R_LIBS).  The reason for the
inconsistency between the specified package and its dependencies seems
to be here:

Where, only for dependencies, .libPaths() is first checked for
installed.packages; but the same check doesn't occur for the specified

Code to reproduce:
a <- file.path(tempdir(), "temp")
install.packages("purrr", dependencies = "Imports", lib = a)
list.dirs(a, recursive = FALSE)

Definition of 'lib' from ?install/packages : "character vector giving
the library directories where to install the packages. Recycled as
needed. If missing, defaults to the first element of .libPaths(). "

So, is this the desired behavior?  It would mean it's ?impossible? to
install a package to another location if it happens to be located
within R_LIBS; it also seems weird to have it work for the specified
package but not its dependencies.

Chase Clark
PhD Candidate
Murphy Lab
Center for Biomolecular Sciences
Department of Medicinal Chemistry and Pharmacognosy
University of Illinois at Chicago

More information about the R-help mailing list