findLiterals: Find all literal language objects in R code object

View source: R/packageAnalysis.R

findLiteralsR Documentation

Find all literal language objects in R code object

Description

This finds all literal values such as TRUE, FALSE, numbers, strings in an R code/language object.

Usage

findLiterals(code,
             walker = mkLiteralCollector(ignoreParams, skipIfFalse = skipIfFalse, ...),
             ignoreParams = TRUE, skipIfFalse = TRUE, ...)

Arguments

code

the R language/code object in which to search for literals.

walker

a code-walker function that traverses the code and tests whether a language object is a literal value and collects it if so.

ignoreParams

a scalar logical value controlling whether to process the code for the default values of parameters/formal arguments in a function object, with FALSE indicating to process them and TRUE meaning we skip/ignore them.

skipIfFalse

a logical value that if TRUE means we ignore code of the form if(FALSE) {...}, i.e., code that cannot be executed.

...

additional arguments that are passed to mkLiteralCollector

Value

This returns the collected values from walker.

Author(s)

Duncan Temple Lang

References

The codetools package.

See Also

findCallsTo

Examples

f = function(x = "abc") {
    a = 1L
    b = 3.1415
    c = "xyz"
    if(a < 10)
        paste(x, c, sep = " - ")
    else
        x
}
findLiterals(f)

duncantl/CodeAnalysis documentation built on May 13, 2024, 7:41 p.m.