Suppose we wish to run a workflow requiring a multitude of packages, and that others may use. We could write:
libsNeeded<-c('vsn', 'RColorBrewer', 'pheatmap', 'ggplot2', 'DESeq2', 'dplyr', 'ashr', 'apeglm', 'openxlsx', 'tidyr')
installedLibs <- libsNeeded[(libsNeeded %in% installed.packages()[,"Package"])] # which are installed locally
missingLibs <- libsNeeded[!(libsNeeded %in% installed.packages()[,"Package"])] # which are not
for (p in libsNeeded) {
if (p %in% missingLibs) { install.packages(p) }
else if (p %in% installedLibs) { update.packages(p) }
}
lapply(libsNeeded, library, character.only = TRUE)
But, what if some of these packages are Bioconductor packages, while others aren't. We could determine which installer to use, e.g., by instead writing:
biocLibs<-BiocManager::available() # obtain list of packages in Bioconductor
cranLibs<-available.packages()[,1] # obtain list of packages in CRAN
Then determining if each of libsNeeded
is in one object, the other object, or both. But, in the process of thinking about this, I noticed that:
all(biocLibs %in% cranLibs)
[1] FALSE
all(cranLibs %in% biocLibs)
[1] TRUE
If all CRAN packages are in bioconductor, then I don't necessarily need to write any functionality to select between install.packages()
and BiocManager::install()
, I could just always use the latter.
But, before doing that, I wanted to ask, is there ever a reason to prefer install.packages()
? And slightly more generally, what about the opposite statement? Aside from those packages that aren't in CRAN, is there every a reason to prefer BiocManager
if both options are available?
Thanks
Not the best title, but answers are good:
NICE find. thank you.
Not related to bioc or base::install.packages ; but one good way to share workflows and avoid other users to install packages (and associated dependencies) is to share a dockerfile with a R install + list of used packages in your workflow. Thus they can run your workflow within the docker and it should work the same way you executed it (same package version, same R version, etc..). check Rocker :https://rocker-project.org/