Home > database >  how to pass the function with arguments inside the memoise
how to pass the function with arguments inside the memoise

Time:03-21

While trying to pass the function inside the memosie i am getting an error of Error in FUN(X[[i]], ...) : object 'condition' not found but if run alone its working fine

This is the sample function actually in my shiny app i am also getting the same error

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)

CodePudding user response:

Use,

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

enter image description here

  • Related