# Testcase inspired by
# https://github.com/rstudio/packrat/issues/602
# Ignore the package argument to requireNamespace when it is a symbol.

# This statement should produce a dependency, since library accepts
# symbols as package names.

# This statement should produce a dependency, since we have a
# literal string.

# These statements should not produce dependencies, since requireNamespace
# does not accept symbols as package names and we have a symbol (pkg) as
# input.
wanted <- c("egg", "toast")
missing <- lapply(wanted, function(pkg) {
  if (!requireNamespace(pkg, quietly = TRUE)) {

# This statement should not produce dependencies, as we cannot read through
# the pkg variable and symbols are not permitted with character.only = TRUE.
pkg <- "breakfast"
library(pkg, character.only = TRUE)

Try the packrat package in your browser

Any scripts or data that you put into this service are public.

packrat documentation built on Jan. 10, 2023, 1:07 a.m.