isSymbol: Helper function for comparing a language object to a...

isSymbolR Documentation

Helper function for comparing a language object to a symbol/name, optionally with one of specified values

Description

When statically analyzing R code, we often want to check if a language object is a name/symbol, and if it is, does its value correspond to one of a set in which we are interested. This function simplifies this predicate test/check which typically involves calls to 3 functions, rather than a single one using this function.

Usage

isSymbol(x, sym = character())
isLiteral(x, type = typeof(x))

Arguments

x

the R language object

sym

an optional character vector. If this is not empty, if x is a name/symbol, we check if the value is in this set.

type

the typeof of x. If the caller has already computed this, they can provide it.

Value

TRUE or FALSE

Author(s)

Nick Ulle, Duncan Temple Lang

See Also

is.name walkCode

Examples

 e1 = quote(foo(x, y, z + 1))
 e2 = quote(foo$bar(x, y, z + 1))

 isSymbol(e1[[1]])
 isSymbol(e2[[1]])

 sapply(e1, isSymbol)
 sapply(e2, isSymbol)

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