如何在 memoise 中传递带参数的函数

how to pass the function with arguments inside the memoise

尝试在 memosie 中传递函数时出现错误 Error in FUN(X[[i]], ...) : object 'condition' not found 但如果 运行 单独工作正常

这是我闪亮的应用程序中的示例函数,我也遇到了同样的错误

library(ggplot2)

meansdf <- data.frame(means = c(13.8, 14.8), condition = 1:2)

testplot <- function(df, x, y) {
  arg <- match.call()
  scale <- 0.5
  p <- ggplot(df, aes(x = eval(arg$x),
                      y = eval(arg$y) * scale,
                      fill = eval(arg$x)))
  p + geom_bar(position = "dodge", stat = "identity")
}

a = memoise::memoise(testplot)

a(meansdf, condition, means)

使用,

a(meansdf, meansdf$condition, meansdf$means)