5
$\begingroup$

I was wondering if there is more elegant way of installing and loading multiple packages in Bioconductor similar to pacman with CRAN packages.

I tried:


# install and load  the package  manager
 if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

# install and load bioconductor packages 
bio_pkgs = c("BiocManager", "ggbio", "biomaRt", "EnsDb.Hsapiens.v75", "cBioPortalData", "GenomicRanges", "GenomicFeatures", "TxDb.Hsapiens.UCSC.hg19.knownGene", "Homo.sapiens")

 if (!requireNamespace(bio_pkgs, quietly = TRUE))
    BiocManager::install(bio_pkgs)

library(easypackages)
libraries("ggbio", "biomaRt", "EnsDb.Hsapiens.v75", "renvcBioPortalData", "GenomicRanges", "GenomicFeatures", "TxDb.Hsapiens.UCSC.hg19.knownGene", "Homo.sapiens")

$\endgroup$

1 Answer 1

7
$\begingroup$

You can do something like this:

bio_pkgs <- c("ggbio", "biomaRt", "EnsDb.Hsapiens.v75", "renvcBioPortalData", 
          "GenomicRanges", "GenomicFeatures", "TxDb.Hsapiens.UCSC.hg19.knownGene", "Homo.sapiens")

# install:
BiocManager::install(bio_pkgs)

# load all at once
invisible(lapply(pkgs, function(x) library(x, character.only=TRUE)))

Be aware though that if you version-control your packages with something like renv then it is encouraged to explicitely load every package as suggested here so renv can properly recognize the packages to snapshot.

$\endgroup$
1
  • $\begingroup$ Thank you ATpoint, this is way more elegant :) $\endgroup$
    – Sam
    Jan 25, 2021 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.