Learn R Programming

renv (version 0.8.0)

dependencies: Find R Package Dependencies in a Project

Description

Find R packages used within a project.

Usage

dependencies(path = getwd(), root = NULL, quiet = FALSE)

Arguments

path

The path to a (possibly multi-mode) R file, or a directory containing such files.

root

The root directory to be used for dependency discovery. Defaults to the active project directory. You may need to set this explicitly to ensure that your project's .renvignores (if any) are properly handled.

quiet

Boolean; report problems discovered (if any) during dependency discovery?

Value

An R data.frame of discovered dependencies, mapping inferred package names to the files in which they were discovered.

Ignoring Files

By default, renv will read your project's .gitignores (if any) to determine whether certain files or folders should be included when traversing directories. If preferred, you can also create a .renvignore file (with entries of the same format as a standard .gitignore file) to tell renv which files to ignore within a directory. If both .renvignore and .gitignore exist within a folder, the .renvignore will be used in lieu of the .gitignore.

See https://git-scm.com/docs/gitignore for documentation on the .gitignore format. Some simple examples here:

# ignore all R Markdown files
*.Rmd

# ignore all data folders data/

# ignore only data folders from the root of the project /data/

Details

dependencies() will crawl files within your project, looking for R files and the packages used within those R files. This is done primarily by parsing the code and looking for calls of the form:

  • library(package)

  • require(package)

  • requireNamespace("package")

  • package::method()

For R package projects, dependencies expressed in the DESCRIPTION file will also be discovered. Note that the rmarkdown package is required in order to crawl dependencies in R Markdown files.

Examples

Run this code
# NOT RUN {
# find R package dependencies in the current directory
renv::dependencies()

# }

Run the code above in your browser using DataLab