r-devel / r-project-sprint-2023

Material for the R project sprint
https://contributor.r-project.org/r-project-sprint-2023/
17 stars 3 forks source link

Vectorize library() #40

Open hturner opened 1 year ago

hturner commented 1 year ago

Discussed in https://github.com/r-devel/r-project-sprint-2023/discussions/15

Originally posted by **gmbecker** July 20, 2023 # Summary `library` currently takes the name of a single package (either in the form of a character vector of length one, or via NSE). I propose `library` accept a vector of packages and load them all (plus their dependnecies) in the order that they appear. # Background. `R` supports versioned dependencies, which nearly always come in the form of `pkg (>= vers)`. `R` also supports vectors of library paths. And, in particular, R supports different versions of the same package appearing at different points in its set of libpaths, at least in principle. In practice these two capabilities combine to form some sharp-edged corner cases where valid, installed packages can be unloadable. # Reason Consider the following dependency structure between packages `pkgA`: `pkgB (>= 0.5.0)` `pkgC`: `pkgB (>= 0.6.0)` Consider the following multi-libpath setup: `~/pth1/`: `pkgA`, `pkg B [0.5.1]` `~/pth2/`: `pkg C`, `pkg B [0.6.5]` And consider that we have the libpath `c("~/pth1/", "~pth2")`. If we do ``` library(pkgA) ``` Things will work great. Same if we do ``` library(pkgC) ``` BUT, if we do ``` library(pkgA) library(pkgC) ``` `pkgC` will not be able to be loaded, because an insufficient version of `pkgB` will already be loaded. # Proposal: Support ``` library(c("pkgA", "pkgC")) ``` Which would result in the following search path: `pkgA`, `pkgB [0.6.5]`, `pkgC`. # Conceptual Feasibility A first pass at this could be simply resolving the recursive dependencies as is currently done, and then combining those for a unification pass at the end. Some care will be needed to get the order right, but I'm confident it's doable. # Technical Approach TBD