% Generated by roxygen2: do not edit by hand % Please edit documentation in R/funscanr.R \name{scan_usage} \alias{scan_usage} \title{Find used functions and packages} \usage{ scan_usage( path = ".", allowed_packages, export_index, origin_map, ignore_unqualified_functions = .stdlib_funs, strict = FALSE, skip_dirs = .scan_skip_dirs, metapackages = NULL, use_knitr = FALSE, quiet = getOption("stanflow.quiet", FALSE) ) } \arguments{ \item{path}{A single project directory (searched recursively) or a vector of files (.R/.Rmd/.qmd).} \item{allowed_packages}{Character vector of package namespaces to attribute calls to.} \item{export_index}{Named list mapping function names to packages.} \item{origin_map}{Named character vector mapping \code{pkg::fun} keys to the origin package.} \item{ignore_unqualified_functions}{Defaults to exports from base R packages listed in \code{stdlib_funs()}. Character vector of function names to ignore when attributing (unqualified) calls to Stan packages. Calls like \code{rstan::plot()} will NOT be ignored even if \code{plot} is in \code{ignore_unqualified_functions}, since they are namespaced.} \item{strict}{If \code{TRUE} (default), only count unqualified function calls whose origin can be determined exactly from the static scan, including attachment-order tie-breaks when the winner is unambiguous from the file. Unresolved calls are warned about and omitted.} \item{skip_dirs}{Character vector of directory names to skip when scanning a directory. Defaults to \code{.scan_skip_dirs}.} \item{metapackages}{Named list mapping attached package names to additional packages that should be treated as co-attached for unqualified resolution. Defaults to \code{NULL}.} \item{use_knitr}{Logical. If \code{TRUE}, parse \code{.Rmd} and \code{.qmd} files with \code{knitr::purl()}. This is more accurate for knitr/quarto chunk extraction but much slower than the default in-house parser. Defaults to \code{FALSE}.} \item{quiet}{Logical. If \code{TRUE}, suppresses status messages.} } \value{ A list of packages, resolved functions, and ambiguous function calls. } \description{ This function is primarily exported for developers. The scanner itself is generic and requires an explicit package universe; \code{stan_cite()} is the Stan-configured entry point. The scanning is wholly static (AST parsing), so there are a number of restrictions on what calls are recognized: calls to \code{library()}, \code{require()}, \code{requireNamespace()}, or \code{use()} are all recognized as attaching a package. } \details{ Explicit package references from \code{library()}, \code{require()}, \code{requireNamespace()}, \code{use()}, and \code{pkg::fun} are only recorded when their package is included in \code{allowed_packages}. Unqualified function calls are only attributed when a package is attached via \code{library()} or \code{require()} in the same file and \code{allowed_packages}, \code{export_index}, and \code{origin_map} describe how to resolve them. Attaching a metapackage can also be treated as attaching additional packages when \code{metapackages} is supplied. When multiple attached packages export the same unqualified function, attachment order is respected: the most recently attached matching package whose attachment appears before the call is treated as the winner. Known reexports are remapped to their origin packages; missing mappings fall back to the resolved package. } \examples{ path <- tempfile(fileext = ".R") writeLines( c( "# one messy analysis file", "library(stats)", "requireNamespace(\"utils\")", "filter(1:10, rep(1, 3))", "utils::head(letters)" ), path ) scan_usage( path, allowed_packages = c("stats", "utils"), export_index = list(filter = "stats"), origin_map = c("stats::filter" = "stats"), ignore_unqualified_functions = character(), quiet = TRUE ) unlink(path) }