Last active
December 10, 2015 21:18
-
-
Save lgatto/4493747 to your computer and use it in GitHub Desktop.
Get/install an R package's dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getDependencies <- function(p, | |
| rep = c("BioCsoft", "BioCann", "BioCexp", "BioCextra", "CRAN"), | |
| biocVersion = "2.12", | |
| depLevels = c("Depends", "Imports", "Suggests"), | |
| filter = TRUE) { | |
| rep <- match.arg(rep) | |
| if (rep == "CRAN") { | |
| rep <- getOption("repos")["CRAN"] | |
| } else { | |
| biocMirror <- getOption("BioC_mirror", "http://bioconductor.org") | |
| biocPaths <- switch(rep, | |
| BioCsoft = "bioc", | |
| BioCann = "data/annotation", | |
| BioCexp = "data/experiment", | |
| BioCextra = "extra") | |
| rep <- paste(biocMirror, | |
| "packages", | |
| biocVersion, | |
| biocPaths, | |
| sep = "/") | |
| } | |
| pDetails <- available.packages(contrib.url(rep))[p, ] | |
| depLevels <- match.arg(depLevels, several.ok = TRUE) | |
| deps <- sapply(depLevels, | |
| function(.depLevel) | |
| tools:::package.dependencies(pDetails, depLevel = .depLevel)[[1]][, 1]) | |
| deps <- unlist(deps) | |
| i <- match("R", deps) | |
| if (length(i) > 0) | |
| deps <- deps[-i] | |
| if (filter) { | |
| installedP <- installed.packages()[,"Package"] | |
| deps <- deps[!deps %in% installedP] | |
| } | |
| return(deps) | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getPackagesInBiocView <- function(view, | |
| rep = c("BioCsoft", "BioCann", | |
| "BioCexp", "BioCextra"), | |
| biocVersion = "2.12") { | |
| suppressPackageStartupMessages(require("biocViews")) | |
| data(biocViewsVocab) | |
| rep <- match.arg(rep) | |
| biocMirror <- getOption("BioC_mirror", "http://bioconductor.org") | |
| biocPaths <- switch(rep, | |
| BioCsoft = "bioc", | |
| BioCann = "data/annotation", | |
| BioCexp = "data/experiment", | |
| BioCextra = "extra") | |
| rep <- paste(biocMirror, | |
| "packages", | |
| biocVersion, | |
| biocPaths, | |
| sep = "/") | |
| bv <- getBiocViews(rep, biocViewsVocab, "NoViewProvided") | |
| if (!view %in% names(bv)) { | |
| message("BiocView ", view, " not found.") | |
| return(NULL) | |
| } | |
| return(bv[[view]]) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| installDependencies <- function(p, ...) { | |
| message("Installing ",p, " dependencies and updating available packages...") | |
| deps <- getDependencies(p, ...) | |
| if (!require(BiocInstaller)) | |
| source("http://bioconductor.org/biocLite.R") | |
| biocLite(deps, ask = FALSE) | |
| invisible(NULL) | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| installPackages <- function(ps) { | |
| installed <- installed.packages()[,"Package"] | |
| ps <- ps[!ps %in% installed] | |
| message("Installing dependencies and updating available packages...") | |
| if (!require(BiocInstaller)) | |
| source("http://bioconductor.org/biocLite.R") | |
| biocLite(ps, ask = FALSE) | |
| invisible(NULL) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment