checkUsage: Check R Code for Possible Problems

Description Usage Arguments Details Author(s) Examples

View source: R/codetools.R

Description

Check R code for possible problems.

Usage

1
2
3
4
5
6
7
8
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, ...) 

Arguments

fun

closure.

name

character; name of closure.

env

environment containing closures to check.

pack

character naming package to check.

...

options to be passed to checkUsage.

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 no examine code portion of with expressions.

suppressUndefined

suppress warnings about undefined global functions and variables.

suppressPartialMatchArgs

suppress warnings about partial argument matching

Details

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.

Author(s)

Luke Tierney

Examples

1
2
3
checkUsage(checkUsage)
checkUsagePackage("codetools",all=TRUE)
## Not run: checkUsagePackage("base",suppressLocal=TRUE)

Example output

addCollectUsageHandler: parameter 'where' may not be used
apdef: parameter 'e' changed by assignment
checkUsageEnterLocal: parameter 'type' changed by assignment
checkUsageFinishLocals: parameter 'w' changed by assignment
collectUsageFun: parameter 'w' changed by assignment
collectUsageIsLocal: parameter 'v' changed by assignment
constantFold : job : isLocal: parameter 'w' may not be used
constantFold : job : doExit: parameter 'e' may not be used
constantFold : job : doExit: parameter 'w' may not be used
constantFoldEnv : isLocal: parameter 'w' may not be used
constantFoldEnv : job : doExit: parameter 'e' may not be used
constantFoldEnv : job : doExit: parameter 'w' may not be used
constantFoldEnv : <anonymous>: parameter 'e' may not be used
constantFoldEnv: parameter 'env' may not be used
evalseq: parameter 'e' changed by assignment
findGlobals : enter: parameter 'e' may not be used
findGlobals : enter: parameter 'w' may not be used
findLocalsList : collect: parameter 'e' may not be used
findLocalsList : collect: parameter 'w' may not be used
findLocalsList : isLocal: parameter 'w' may not be used
findOwnerEnv: parameter 'env' changed by assignment
foldLeaf: parameter 'e' changed by assignment
getCollectLocalsHandler : <anonymous>: parameter 'e' may not be used
getCollectLocalsHandler : <anonymous>: parameter 'w' may not be used
getCollectLocalsHandler : <anonymous>: parameter 'e' may not be used
getCollectLocalsHandler : <anonymous>: parameter 'w' may not be used
isClosureFunDef: parameter 'w' may not be used
isConstantValue: parameter 'w' may not be used
makeAssgnFcn: parameter 'fun' changed by assignment
makeCodeWalker : <anonymous>: parameter 'v' may not be used
makeCodeWalker : <anonymous>: parameter 'w' may not be used
makeCodeWalker : <anonymous>: parameter 'w' may not be used
makeConstantFolder : <anonymous>: parameter 'w' may not be used
makeConstantFolder : <anonymous>: parameter 'v' may not be used
makeConstantFolder : <anonymous>: parameter 'w' may not be used
makeConstantFolder : <anonymous>: parameter 'e' may not be used
makeConstantFolder : <anonymous>: parameter 'w' may not be used
makeConstantFolder: parameter 'foldable' may not be used
makeLocalsCollector : <anonymous>: parameter 'e' may not be used
makeLocalsCollector : <anonymous>: parameter 'w' may not be used
makeLocalsCollector : <anonymous>: parameter 'v' may not be used
makeLocalsCollector : <anonymous>: parameter 'w' may not be used
makeLocalsCollector : <anonymous>: parameter 'e' may not be used
makeLocalsCollector : <anonymous>: parameter 'w' may not be used
makeLocalsCollector : <anonymous>: parameter 'e' may not be used
makeLocalsCollector : <anonymous>: parameter 'w' may not be used
makeLocalsCollector: parameter 'exit' may not be used
walkCode: local variable 'h' used as function with no apparent local function definition

codetools documentation built on Nov. 8, 2020, 4:31 p.m.