Skip to content

Instantly share code, notes, and snippets.

@minjejeon
Created August 25, 2016 02:43
Show Gist options
  • Select an option

  • Save minjejeon/d4007f5cd68ce8df1562c204a835a22c to your computer and use it in GitHub Desktop.

Select an option

Save minjejeon/d4007f5cd68ce8df1562c204a835a22c to your computer and use it in GitHub Desktop.
R 패키지 다운로드
instPkgPlusDeps <- function(pkg, download = TRUE,
which = c("Depends", "Imports", "LinkingTo"),
inc.pkg = TRUE) {
stopifnot(require("tools")) ## load tools
ap <- available.packages() ## takes a minute on first use
## get dependencies for pkg recursively through all dependencies
deps <- package_dependencies(pkg, db = ap, which = which, recursive = TRUE)
## the next line can generate warnings; I think these are harmless
## returns the Priority field. `NA` indicates not Base or Recommended
pri <- sapply(deps[[1]], packageDescription, fields = "Priority")
## filter out Base & Recommended pkgs - we want the `NA` entries
deps <- deps[[1]][is.na(pri)]
## install pkg too?
if (inc.pkg) {
deps = c(pkg, deps)
}
## are we downloading?
if (download) {
download.packages(deps, destdir = '~/rpackage', type = 'source')
}
deps ## return dependencies
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment