Skip to content

Commit

Permalink
additional experimentation and refinement of renv dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
aronatkins committed Nov 10, 2021
1 parent acabe10 commit a6d806c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ dirDependencies <- function(dir) {
}
}

# Return renv ignore patterns based on the packrat ignored.directories option.
# Each directory is returned as a rooted pattern for renv, meaning that it
# should only apply at the root directory of the project.
#
# Note: The "/data/" and "/inst/" directories are ignored by default.
ignoredDirsForRenv <- function(ignoredDirs) {
if (length(ignoredDirs) > 0) {
# Make sure all the directories end with a slash.
ignoredDirs <- ifelse(
substr(ignoredDirs, nchar(ignoredDirs), nchar(ignoredDirs)) != "/",
paste0(ignoredDirs, "/"),
ignoredDirs
)
# Make sure all the directories begin with a slash.
ignoredDirs <- ifelse(
substr(ignoredDirs, 1, 1) != "/",
paste0("/", ignoredDirs),
ignoredDirs
)
ignoredDirs
}
}

dirDependenciesRenv <- function(dir) {
old <- options(renv.config.filebacked.cache = FALSE)
on.exit(do.call(options, old), add = TRUE)
Expand All @@ -132,7 +155,13 @@ dirDependenciesRenv <- function(dir) {
}

deps <- renv$dependencies(path = dir, quiet = TRUE)
unique(deps$Package)
pkgs <- unique(deps$Package)
# remove accidents.
# https://github.com/rstudio/renv/issues/858
pkgs <- setdiff(pkgs, c("R"))
## Exclude recommended packages if there is no package installed locally
## this places an implicit dependency on the system-installed version of a package
dropSystemPackages(pkgs)
}

# detect all package dependencies for a directory of files
Expand Down

0 comments on commit a6d806c

Please sign in to comment.