Title: | Code Analysis Tools for R |
---|---|
Description: | Code analysis tools for R. |
Authors: | Luke Tierney <[email protected]> |
Maintainer: | Luke Tierney <[email protected]> |
License: | GPL |
Version: | 0.2-20 |
Built: | 2024-06-15 17:27:55 UTC |
Source: | CRAN |
Check R code for possible problems.
checkUsage(fun, name = "<anonymous>", report = cat, all = FALSE, suppressLocal = FALSE, suppressParamAssigns = !all, suppressParamUnused = !all, suppressFundefMismatch = FALSE, suppressLocalUnused = FALSE, suppressNoLocalFun = !all, skipWith = FALSE, suppressUndefined = dfltSuppressUndefined, suppressPartialMatchArgs = TRUE) checkUsageEnv(env, ...) checkUsagePackage(pack, ...)
checkUsage(fun, name = "<anonymous>", report = cat, all = FALSE, suppressLocal = FALSE, suppressParamAssigns = !all, suppressParamUnused = !all, suppressFundefMismatch = FALSE, suppressLocalUnused = FALSE, suppressNoLocalFun = !all, skipWith = FALSE, suppressUndefined = dfltSuppressUndefined, suppressPartialMatchArgs = TRUE) checkUsageEnv(env, ...) checkUsagePackage(pack, ...)
fun |
closure. |
name |
character; name of closure. |
env |
environment containing closures to check. |
pack |
character naming package to check. |
... |
options to be passed to |
report |
function to use to report possible problems. |
all |
logical; report all possible problems if TRUE. |
suppressLocal |
suppress all local variable warnings. |
suppressParamAssigns |
suppress warnings about assignments to formal parameters. |
suppressParamUnused |
suppress warnings about unused formal parameters. |
suppressFundefMismatch |
suppress warnings about multiple local function definitions with different formal argument lists |
suppressLocalUnused |
suppress warnings about unused local variables |
suppressNoLocalFun |
suppress warnings about using local variables as functions with no apparent local function definition |
skipWith |
logical; if true, do not examine code portion of
|
suppressUndefined |
suppress warnings about undefined global functions and variables. |
suppressPartialMatchArgs |
suppress warnings about partial argument matching |
checkUsage
checks a single R closure. Options control which
possible problems to report. The default settings are moderately
verbose. A first pass might use suppressLocal=TRUE
to
suppress all information related to local variable usage.
The suppressXYZ
values can either be scalar logicals or
character vectors; then they are character vectors they only
suppress problem reports for the variables with names in the vector.
checkUsageEnv
and checkUsagePackage
are convenience
functions that apply checkUsage
to all closures in an
environment or a package. checkUsagePackage
requires that the
package be loaded. If the package has a name space then the internal
name space frame is checked.
Luke Tierney
checkUsage(checkUsage) checkUsagePackage("codetools",all=TRUE) ## Not run: checkUsagePackage("base",suppressLocal=TRUE)
checkUsage(checkUsage) checkUsagePackage("codetools",all=TRUE) ## Not run: checkUsagePackage("base",suppressLocal=TRUE)
These functions provide some tools for analysing R code. Mainly intended to support the other tools in this package and byte code compilation.
collectLocals(e, collect) collectUsage(fun, name = "<anonymous>", ...) constantFold(e, env = NULL, fail = NULL) findFuncLocals(formals, body) findLocals(e, envir = .BaseEnv) findLocalsList(elist, envir = .BaseEnv) flattenAssignment(e) getAssignedVar(e) isConstantValue(v, w) makeCodeWalker(..., handler, call, leaf) makeConstantFolder(..., leaf, handler, call, exit, isLocal, foldable, isConstant, signal) makeLocalsCollector(..., leaf, handler, isLocal, exit, collect) makeUsageCollector(fun, ..., name, enterLocal, enterGlobal, enterInternal, startCollectLocals, finishCollectLocals, warn, signal) walkCode(e, w = makeCodeWalker())
collectLocals(e, collect) collectUsage(fun, name = "<anonymous>", ...) constantFold(e, env = NULL, fail = NULL) findFuncLocals(formals, body) findLocals(e, envir = .BaseEnv) findLocalsList(elist, envir = .BaseEnv) flattenAssignment(e) getAssignedVar(e) isConstantValue(v, w) makeCodeWalker(..., handler, call, leaf) makeConstantFolder(..., leaf, handler, call, exit, isLocal, foldable, isConstant, signal) makeLocalsCollector(..., leaf, handler, isLocal, exit, collect) makeUsageCollector(fun, ..., name, enterLocal, enterGlobal, enterInternal, startCollectLocals, finishCollectLocals, warn, signal) walkCode(e, w = makeCodeWalker())
e |
R expression. |
elist |
list of R expressions. |
v |
R object. |
fun |
closure. |
formals |
formal arguments of a closure. |
body |
body of a closure. |
name |
character. |
env |
character. |
envir |
environment. |
w |
code walker. |
... |
extra elements for code walker. |
collect |
function. |
fail |
function. |
handler |
function. |
call |
function. |
leaf |
function. |
isLocal |
function. |
exit |
function. |
enterLocal |
function. |
enterGlobal |
function. |
enterInternal |
function. |
startCollectLocals |
function. |
finishCollectLocals |
function. |
warn |
function. |
signal |
function. |
isConstant |
function. |
foldable |
function. |
Luke Tierney
Finds global functions and variables used by a closure.
findGlobals(fun, merge = TRUE)
findGlobals(fun, merge = TRUE)
fun |
function object; usually a closure. |
merge |
logical |
The result is an approximation. R semantics only allow variables
that might be local to be identified (and event that assumes no use
of assign
and rm
).
Character vector if merge
is true; otherwise, a list with
functions
and variables
character vector components.
Character vectors are of length zero For non-closures.
Luke Tierney
findGlobals(findGlobals) findGlobals(findGlobals, merge = FALSE)
findGlobals(findGlobals) findGlobals(findGlobals, merge = FALSE)
Prints a Lisp-style representation of R expression. This can be useful for understanding how some things are parsed.
showTree(e, write = cat)
showTree(e, write = cat)
e |
R expression. |
write |
function of one argument to write the result. |
Luke Tierney
showTree(quote(-3)) showTree(quote("x"<-1)) showTree(quote("f"(x)))
showTree(quote(-3)) showTree(quote("x"<-1)) showTree(quote("f"(x)))