考虑一个简单的函数,它为grob添加了一个ggtitle
f <- function(PLOT, TITLE) {
PLOT + ggtitle(TITLE)
}直接调用函数就像预期的那样工作。
但是,当do.call(f, ..)是language对象时,通过language调用函数会引发错误。
## Sample Data
TIT <- bquote(atop("This is some text", atop(italic("Here is some more text"))))
P <- qplot(x=1:10, y=1:10, geom="point")
## WORKS FINE
f(P, TIT)
## FAILS
do.call(f, list(P, TIT))
## Error in labs(title = label) : could not find function "atop"当然,只有当TIT是语言对象时才会发生这种情况。
TIT.char <- "This is some text\nHere is some more text"
do.call(f, list(P, TIT.char))
## No Error当参数是语言对象时,如何正确地使用do.call()?
发布于 2015-05-07 17:20:03
使用
do.call(f, list(P, TIT), quote=TRUE)而不是。问题是,在运行do.call时,将对表达式进行评估。通过设置quote=TRUE,它将引用参数,使它们在传递给f时保持未求值。您也可以显式引用TIT
do.call(f, list(P, quote(TIT)))https://stackoverflow.com/questions/30107702
复制相似问题