att_from_rscript: Look for functions called with '::' and library/requires in...

View source: R/att_from_rscripts.R

att_from_rscriptR Documentation

Look for functions called with :: and library/requires in one script

Description

Look for functions called with :: and library/requires in one script

Usage

att_from_rscript(path, encoding = getOption("encoding"))

Arguments

path

path to R script file

encoding

Encoding passed to readLines() when reading path. Defaults to getOption("encoding") so the system locale is respected (important on Windows where scripts are often Latin-1 / Windows-1252).

Details

Uses the R parser to walk the syntax tree so that occurrences of pkg::fun or library()/require()/requireNamespace()/loadNamespace()/use()/getFromNamespace() inside string literals or comments are ignored. Named arguments such as library(package = "pkg") are supported, as are fully-qualified forms like base::library(pkg) or methods::getFromNamespace(fn, "pkg"). Introspection helpers such as packageVersion(), getNamespace(), asNamespace(), and attachNamespace() are not treated as dependency introducers, because they are commonly used for version or feature checks on packages that may or may not be required at runtime.

If the file cannot be parsed as valid R (syntax error, corrupt encoding, etc.), the function falls back to a regex-based detector and emits a warning() naming the file so users can investigate.

Value

a vector

Examples

dummypackage <- system.file("dummypackage",package = "attachment")
# browseURL(dummypackage)

att_from_rscript(path = file.path(dummypackage,"R","my_mean.R"))

attachment documentation built on April 25, 2026, 9:06 a.m.