fNameFinder: Find a function name when the function is passed as an...

Description Usage Arguments Details Value Examples

View source: R/2DLTfunctions.r

Description

Find a function name when the function is passed as an argument into other functions.

Usage

1
fNameFinder(x, fSearchSting = "fName")

Arguments

x

an R function/method that has not been evaluated.

fSearchSting='fName'

function name search string

Details

The function passed into x the x argument must have the object fSearchSting within its body. The fSearchSting must be the only code on a line within the function, but can be placed anywhere in the function body, e.g. fName='f1'. See examples.

Value

Returns a character string e.g. "fName='f1'" that can be evaluated using eval(parse(text="fName='f1'") either outside of a function, see example or within the scope of a function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
##Example 1 - check this approach works with nested functions
f1=function(x) {
fName='f1'
x**2}

f2=function(f,y){
 res=f(x=y)
 funcName1=fNameFinder(f)
 return(list(res,funcName1))}

f3=function(f,y){
 res=f2(f,y)
 return(res)}

eval(parse(text=f3(f=f1,y=2)[[2]]))

david-borchers/LT2D documentation built on Aug. 17, 2020, 1:37 a.m.