Something went wrong. Try again.
[mirror] R Package for a Mildly Opinionated Stan Bayesian Workflow stanflow.visruth.com
Something went wrong. Try again.
3.9 kB · 103 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104% 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 offiles (.R/.Rmd/.qmd).}
\item{allowed_packages}{Character vector of package namespaces to attributecalls to.}
\item{export_index}{Named list mapping function names to packages.}
\item{origin_map}{Named character vector mapping \code{pkg::fun} keys to theorigin package.}
\item{ignore_unqualified_functions}{Defaults to exports from base R packageslisted in \code{stdlib_funs()}. Character vector of function names to ignore whenattributing (unqualified) calls to Stan packages. Calls like \code{rstan::plot()}will NOT be ignored even if \code{plot} is in \code{ignore_unqualified_functions}, sincethey are namespaced.}
\item{strict}{If \code{TRUE} (default), only count unqualified function callswhose origin can be determined exactly from the static scan, includingattachment-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 adirectory. Defaults to \code{.scan_skip_dirs}.}
\item{metapackages}{Named list mapping attached package names to additionalpackages 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 extractionbut 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 isgeneric and requires an explicit package universe; \code{stan_cite()} is theStan-configured entry point.The scanning is wholly static (AST parsing), so there area 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 theirpackage is included in \code{allowed_packages}. Unqualified function calls areonly attributed when a package is attached via \code{library()} or \code{require()} inthe 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 asattaching additional packages when \code{metapackages} is supplied. When multipleattached packages export the same unqualified function, attachment order isrespected: the most recently attached matching package whose attachmentappears before the call is treated as the winner. Known reexports areremapped to their origin packages; missing mappings fall back to theresolved 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)}