I wrote a function that uses match.call, and it works when I call the function directly, however, when the function is called within another function it breaks. I believe it has to do with how match.call handles environments, but I can't figure it out. Here is a reproducable example:
tester <- function() {
var <- "helloworld"
myFunc(var)
}
myFunc <- function(x) {
tmp <- match.call()
tmp[[1]] <- quote(toupper)
eval(tmp)
}
tester() # error
myFunc("helloworld") # works fine
I believe that when myFunc is called within tester it can't find var because it exists in the isolated environment of the tester function.
Any ideas on how to get myFunc to work inside tester would be appreciated. I've tried changing the environment for eval and match.call, but to no avail.