Skip to contents

This function is primarily exported for developers, and is almost entirely divested from stanflow, except for defaults and {stanflow} behavior explained later.

Usage

scan_usage(
  path = ".",
  ignore_unqualified_functions = .stdlib_funs,
  strict = FALSE,
  skip_dirs = .scan_skip_dirs,
  allowed_packages = .stan_pkgs,
  export_index = .stan_export_index,
  origin_map = .stan_origin_map,
  quiet = getOption("stanflow.quiet", FALSE)
)

Arguments

path

A single project directory (searched recursively) or a vector of files (.R/.Rmd/.qmd).

ignore_unqualified_functions

Defaults to exports from base R packages listed in stdlib_funs(). Character vector of function names to ignore when attributing (unqualified) calls to Stan packages. Calls like rstan::plot() will NOT be ignored even if plot is in ignore_unqualified_functions, since they are namespaced.

strict

If TRUE, only count unqualified function calls that resolve to a single Stan package.

skip_dirs

Character vector of directory names to skip when scanning a directory. Defaults to .scan_skip_dirs.

allowed_packages

Character vector of package namespaces to attribute to Stan usage. Defaults to .stan_pkgs.

export_index

Named list mapping function names to packages. Defaults to .stan_export_index.

origin_map

Named character vector mapping pkg::fun keys to the origin package. Defaults to .stan_origin_map.

quiet

Logical. If TRUE, suppresses status messages.

Value

A list of packages, resolved functions, and ambiguous function calls.

Details

The scanning is wholly static (AST parsing), so there are a number of restrictions on what calls are recognized: calls to library(), require(), requireNamespace(), or use() are all recognized as attaching a package.

The Stan values for allowed_packages, export_index, and origin_map are generated by data_raw/sysdata.R.

Unqualified function calls are only attributed when a Stan package is attached via library() or require() in the same file. Attaching {stanflow} is hardcoded as attaching its core packages (bayesplot, loo, posterior, projpred, shinystan). Known reexports are remapped to their origin packages; missing mappings fall back to the resolved package.