freeVariables: Find undefined variables in top-level R code/script

freeVariablesR Documentation

Find undefined variables in top-level R code/script

Description

This statically analyzes the code and finds variables that may be used directly but that are not previously defined. This optionally can take into account code that is sourced, variables that are available via the code loading packages, and variables that are created via load. This is analogous to getGlobals and findGlobals but for R scripts rather than functions.

Usage

freeVariables(sc, load = TRUE, packages = TRUE, includeSource = TRUE,
              exclude = getSearchPathVariables(), inputs = getInputs(sc))

Arguments

sc

the R code, either created via parse or the name(s) of a file or directory containing R code.

load

a logical value controlling whether to read files that are loaded in the code to determine the names of the variables that would be created.

packages

a logical value that controls whether to determine the names of the variables that become available to the code when a packge is loaded via library or require calls in the code.

includeSource

a logical value controlling whether this function processes calls to source in the code analysis by replacing the call to source with the contents of the file that would be source'd.

exclude

which variables to exclude from the undefined variables, but treat as being externally defined.

inputs

typically not provided but the ScriptInfo computed on the code after source commands have been substituted with the actual code from those R files.

Value

a character vector

Author(s)

Duncan Temple Lang

See Also

getGlobals findGlobals


duncantl/CodeAnalysis documentation built on Feb. 21, 2024, 10:49 p.m.