lsAccessibleVariable: list accessible variables of a function

View source: R/lsAccessibleVariable.R

lsAccessibleVariableR Documentation

list accessible variables of a function

Description

List the variables that a function can access

Usage

lsAccessibleVariable(fun, printValue = FALSE, variable2print = NULL)

Arguments

fun

function object.

printValue

logical, if TRUE, print the value of each variable that the fun can access. The default is FALSE.

variable2print

character or vector of charactor or NULL. If it's NULL and printValue is TRUE, the value of all variables will be printed. If this is a (vector of) character and printValue is TRUE, then the value(s) of variable(s) indicated by this (vector of) character will be printed. When there is no such variable indicated by variable2print, a warning will be raised.

Value

the name(s) of variable(s) which can be accessed by 'fun' function.

Examples

## Not run: 
a = 1
f = function(b) {
  ab = 2
  innerF = function(c) ab * b * c
  return(innerF)
}
funObj = f(2)

lsAccessibleVariable(f) # global environment.
lsAccessibleVariable(funObj) # environment within function f.
lsAccessibleVariable(funObj, T) # all variables in environment within function f.
lsAccessibleVariable(funObj, T, "ab") # variables 'ab' in environment within function f.

## End(Not run)

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.