Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting alternate default paths #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(any_local_behind_lockfile)
export(capshot)
export(capshot_str)
export(capsule_sources)
export(compare_capsule_to_lockfile)
export(compare_local_to_lockfile)
export(create)
Expand Down
7 changes: 4 additions & 3 deletions R/capshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ BASE_PACKAGES <-
#' be integrated into automated pipelines that build projects or documents.
#'
#' @param dep_source_paths files to scan for project dependencies to write to the lock file.
#' Defaults to './packages.R`. See [capsule_sources()] for setting other defaults.
#' @param lockfile_path output path for the lock file.
#' @param minify a boolean value indicicating if lockfile JSON should have whitespace removed to shrink footprint.
#'
#' @return `lockfile_path`. Writes lockfile as a side effect.
#' @export
capshot <- function(
dep_source_paths = "./packages.R",
dep_source_paths = capsule_sources(),
lockfile_path = "./renv.lock",
minify = FALSE
) {
Expand All @@ -69,7 +70,7 @@ capshot <- function(

#' @describeIn capshot a variation that returns lockfile json as a character vector for further use.
#' @export
capshot_str <- function(dep_source_paths = "./packages.R", minify = FALSE) {
capshot_str <- function(dep_source_paths = capsule_sources(), minify = FALSE) {
generate_lockfile_json(
get_project_deps(detect_dependencies(dep_source_paths)),
minify = minify
Expand Down Expand Up @@ -104,7 +105,7 @@ get_project_dcfs <- function(declared_deps, pkg_names, pkg_dcfs) {
current_deps <- new_current_deps
}
missing <- setdiff(names(project_deps), unlist(pkg_names))
if (length(missing)) stop("Cannot complete capshot(). Project dependencies not installed locally: ",
if (length(missing)) stop("Cannot complete capshot(). Project dependencies not installed locally: ",
paste(missing, collapse = ", "), "\n\n",
"Use dev_mirror_lockfile() to bring the local library up to at least the lockfile versions for all dependencies."
)
Expand Down
20 changes: 20 additions & 0 deletions R/capsule_sources.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
##' Get the default files from which to detect dependencies
##'
##' Dependencies to be encapsulated are detected from R files in your repository.
##' A single `./packages.R` file is the default, but you can provide a
##' vector of paths directly, using the R global option `capsule.sources`, or
##' the environment variable `CAPSULE_SOURCES` (the latter takes only a single
##' file name). Using a single file with all library() calls makes an explicit
##' assertion of your dependencies. This way spurious usages of pkg:: for
##' packages not stated as dependencies will cause errors that can be caught.
##'
##' @title capsule_sources
##' @param paths The default files in which to look for dependencies
##' @author Noam Ross
##' @export
capsule_sources <- function(paths = "./packages.R") {
getOption(
"capsule.sources",
default = Sys.getenv("CAPSULE_SOURCES", unset = paths)
)
}
5 changes: 3 additions & 2 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
##' file that contains all library() calls - hence this makes an explicit
##' assertion of your dependencies. This way spurious usages of pkg:: for
##' packages not stated as dependencies will cause errors that can be caught.
##'
##'
##' @title create
##' @param dep_source_paths files to find package dependencies in.
##' Defaults to './packages.R`. See [capsule_sources()] for setting other defaults.
##' @return nothing. Creates a capsule as a side effect.
##' @author Miles McBain
##' @export
create <- function(
dep_source_paths = "./packages.R",
dep_source_paths = capsule_sources(),
lockfile_path = "./renv.lock"
) {

Expand Down
7 changes: 4 additions & 3 deletions R/recreate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
##' Similarly to `create()`, you are expected to supply a vector of files in
##' your project to extract dependencies from. Things work best when this is a
##' single file containing only dependency related code.
##'
##'
##' @title recreate
##' @param dep_source_paths a character vector of project source files to
##' extract dependencies from.
##' extract dependencies from. Defaults to './packages.R`.
##' See [capsule_sources()] for setting other defaults.
##' @return nothing. The capsule is regenerated as a side effect.
##' @author Miles McBain
##' @seealso [create()]
##' @export
recreate <- function(dep_source_paths = "./packages.R") {
recreate <- function(dep_source_paths = capsule_sources()) {

delete()
create(dep_source_paths = dep_source_paths)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ The following package(s) will be updated in the lockfile:

You supply a vector of file paths to extract dependencies from. The default is
`"./packages.R"`. These dependencies are copied from your regular (dev) library
to your local capsule.
to your local capsule. These can also be set at the user or project level with
`options(capsule.sources = <PATHS>)`, or a `CAPSULE_SOURCES` environment variable.

Notice how this is easier when you keep your library calls all in one place? :wink:

Expand Down
11 changes: 6 additions & 5 deletions man/capshot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/capsule_sources.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/compare_lockfile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/get_behind.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/recreate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.