Give two functions
subfun <- function(txt)
gsubfn::gsubfn("§([^§]+)§", ~eval(parse(text=x)), txt)
topfun <- function(id = 1L)
subfun("Hello §id§ world!")
The following (1.) should give "Hello 1 world!", but instead produces an error:
topfun()
# Error in eval(expr, envir, enclos) : object 'id' not found
These two (2.) and (3.) work as expected:
id <- 2L
topfun()
# [1] "Hello 2 world!"
topfun2 <- function(id = 1L)
gsubfn::gsubfn("§([^§]+)§", ~eval(parse(text=x)), "Hello §id§ world!")
topfun2()
# [1] "Hello 1 world!"
How can I do the job (1.)?
I tried a few options environment()and parent.frame()a parameter envir evaland gsubfnincluding the transmission topfunmedium on subfunusing the ellipsis argument. All without success. (Not that I knew more about what was going on under the hood. But I would expect R to go into one parent environment after another to search id...)
I use R version 3.3.0and gsubfnversion of the package 0.6.6.
Thanks in advance!
lukeA