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 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))

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


1 Answer 1


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:

# 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.

  • $\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 you have read our privacy policy.

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