Warning, /tutorial-developing-benchmarks/bin/dependencies.R is written in an unsupported language. File is not indexed.
0001 install_required_packages <- function(lib = NULL, repos = getOption("repos", default = c(CRAN = "https://cran.rstudio.com/"))) {
0002
0003 if (is.null(lib)) {
0004 lib <- .libPaths()[[1]]
0005 }
0006
0007 message("lib paths: ", paste(lib, collapse = ", "))
0008 # Note: RMarkdown is needed for renv to detect packages in Rmd documents.
0009 required_pkgs <- c("rprojroot", "desc", "remotes", "renv", "BiocManager", "rmarkdown")
0010 installed_pkgs <- rownames(installed.packages(lib.loc = lib))
0011 missing_pkgs <- setdiff(required_pkgs, installed_pkgs)
0012
0013 # The default installation of R will have "@CRAN@" as the default repository,
0014 # which directs contrib.url() to either force the user to choose a mirror if
0015 # interactive or fail if not. Since we are not interactve, we need to force
0016 # the mirror here.
0017 if ("@CRAN@" %in% repos) {
0018 repos <- c(CRAN = "https://cran.rstudio.com/")
0019 }
0020
0021 if (length(missing_pkgs) != 0) {
0022 install.packages(missing_pkgs, lib = lib, repos = repos)
0023 }
0024 }
0025
0026 find_root <- function() {
0027
0028 cfg <- rprojroot::has_file_pattern("^_config.y*ml$")
0029 root <- rprojroot::find_root(cfg)
0030
0031 root
0032 }
0033
0034 # set the BiocManager repositories and return a function that resets the default
0035 # repositories.
0036 #
0037 # @example
0038 # bioc_repos_example <- function() {
0039 # message("User repos")
0040 # as.data.frame(getOption("repos"))
0041 # reset_repos <- use_bioc_repos()
0042 # on.exit(reset_repos())
0043 # message("Bioc repos")
0044 # as.data.frame(getOption("repos"))
0045 # }
0046 # bioc_repos_example()
0047 # as.data.frame(getOption("repos")
0048 use_bioc_repos <- function() {
0049 repos <- getOption("repos")
0050 suppressMessages(options(repos = BiocManager::repositories()))
0051 function() {
0052 options(repos = repos)
0053 }
0054 }
0055
0056 identify_dependencies <- function() {
0057
0058 root <- find_root()
0059
0060 reset_repos <- use_bioc_repos()
0061 on.exit(reset_repos(), add = TRUE)
0062 eps <- file.path(root, "_episodes_rmd")
0063 bin <- file.path(root, "bin")
0064
0065 required_pkgs <- unique(c(
0066 ## Packages for episodes
0067 renv::dependencies(eps, progress = FALSE, error = "ignored")$Package,
0068 ## Packages for tools
0069 renv::dependencies(bin, progress = FALSE, error = "ignored")$Package
0070 ))
0071
0072 required_pkgs
0073 }
0074
0075 create_description <- function(required_pkgs) {
0076 d <- desc::description$new("!new")
0077 d$set_deps(data.frame(type = "Imports", package = required_pkgs, version = "*"))
0078 d$write("DESCRIPTION")
0079 # We have to write the description twice to get the hidden dependencies
0080 # because renv only considers explicit dependencies.
0081 #
0082 # This is needed because some of the hidden dependencis will require system
0083 # libraries to be configured.
0084 suppressMessages(repo <- BiocManager::repositories())
0085 deps <- remotes::dev_package_deps(dependencies = TRUE, repos = repo)
0086 deps <- deps$package[deps$diff < 0]
0087 if (length(deps)) {
0088 # only create new DESCRIPTION file if there are dependencies to install
0089 d$set_deps(data.frame(type = "Imports", package = deps, version = "*"))
0090 d$write("DESCRIPTION")
0091 }
0092 }
0093
0094 install_dependencies <- function(required_pkgs, ...) {
0095
0096 reset_repos <- use_bioc_repos()
0097 on.exit(reset_repos(), add = TRUE)
0098
0099 create_description(required_pkgs)
0100 on.exit(file.remove("DESCRIPTION"), add = TRUE)
0101 remotes::install_deps(dependencies = TRUE, ...)
0102
0103 if (require("knitr") && packageVersion("knitr") < '1.9.19') {
0104 stop("knitr must be version 1.9.20 or higher")
0105 }
0106
0107 }