Skip to contents

Get dependencies using renv. This function will inspect your package specified at pkg_path (default is current working directory, .), and create an renv lock file (renv.lock) in the docker/ directory. More information about the renv implementation is provided in the Details section.

Usage

renv_deps(
  pkg_path = ".",
  img_path = NULL,
  other_packages = NULL,
  overwrite = TRUE,
  consent_renv = TRUE
)

Arguments

pkg_path

Path to the package directory. Default is "." for the current working directory, which assumes developer is working in R package root. However, this can be set to another path as needed.

img_path

Path to the write the docker image definition contents. The default NULL will use docker/ as a subdirectory of the pkg_path.

other_packages

Vector of other packages to be included in renv lock file; default is NULL.

overwrite

Logical; should an existing lock file should be overwritten? Default is TRUE.

consent_renv

Logical; give renv consent in this session with options(renv.consent = TRUE)? Default is TRUE. See renv::consent for details.

Value

Invisibly returns a list of package info returned by pkg_info. Primarily called for side effect. Writes an renv lock file to the docker/ directory.

Details

The renv.lock file will capture all your package's dependencies (and all their dependencies) at the current version installed on your system at the time this function is run. When using the default use_renv=TRUE in use_docker or add_dockerfile, the resulting Dockerfile will install packages from this renv.lock file using renv::restore. This ensures that versions of dependencies in the image mirror what is installed on your system at the time of image creation, rather than potentially newer versions on package repositories like CRAN or Bioconductor, which may come with breaking changes that you are unaware of at the time of package development.

If there are additional R packages that may be useful for the Docker image you plan to build (but may not be captured under your package dependencies), then you can add these packages to the renv procedure with the "other_packages" argument.

This function is run as part of use_docker but can be used on its own.

Examples

if (FALSE) {
# Specify path to example package source and copy to tempdir()
# Note that in practice you do not need to copy to a tempdir()
# And in fact it may be easiest to use pracpac relative to your package directory root
ex_pkg_src <- system.file("hellow", package = "pracpac", mustWork = TRUE)
file.copy(from = ex_pkg_src, to = tempdir(), recursive = TRUE)

# Run using defaults; only gets current package dependencies
renv_deps(pkg_path = file.path(tempdir(), "hellow"))
# Add additional packages not explicitly required by your package
renv_deps(pkg_path = file.path(tempdir(), "hellow"), other_packages=c("shiny", "knitr"))
}