最后一个例子过去可以工作,现在不行了。函数内部没有字符串插值?也许它与变量范围有关?有什么建议么?
library(gsubfn)
#R.Version() # I'm using 2.15.0, just upgraded from 2.13.something.
### dumb example of a function
g <- function() {for (a in 1:2) { print(paste('is a', a)) }}
g()
### same thing, outside a function, using string interpolation
for (a in 1:2) { fn$print('is a $a') }
rm(a)
### and now string interpolation inside a function
h <- function() {for (a in 1:2) { fn$print('is a $a') }}
h()
最后一个例子告诉我
Error in eval(expr, envir, enclos) : object 'a' not found