Chase Clark
2019-Sep-09 02:14 UTC
[R] install.packages handles package vs package dependencies differently
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: https://github.com/wch/r-source/blob/d6c208e464d20adc6ce080ecfaaab4ccf3f06271/src/library/utils/R/packages2.R#L84-L88 Where, only for dependencies, .libPaths() is first checked for installed.packages; but the same check doesn't occur for the specified package. Code to reproduce: ``` a <- file.path(tempdir(), "temp") dir.create(a) 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. Best, Chase Clark PhD Candidate Murphy Lab Center for Biomolecular Sciences Department of Medicinal Chemistry and Pharmacognosy University of Illinois at Chicago