Why does this trellised velvet wrap not work?

I am trying to create a wrapper for a trellised barchart function similar to this (to use the default ggplot theme):

require(ggplot2)
require(lattice)
require(latticeExtra)
data(Titanic)
mytheme = ggplot2like()
gbarchart = function(...) {
    barchart(..., par.settings=mytheme)
}
gbarchart(Class ~ Freq | Sex + Age,
          as.data.frame(Titanic),
          groups = Survived,
          stack = TRUE,
          layout = c(4, 1),
          auto.key = list(title = "Survived", columns = 2),
          scales = list(x = "free"))

This gives an error:

Error in eval(expr, envir, enclos) : 
  ..3 used in an incorrect context, no ... to look in

So far, if par.settings=mythemeadded to barchartdirectly, it works:

barchart(Class ~ Freq | Sex + Age,
          as.data.frame(Titanic),
          groups = Survived,
          stack = TRUE,
          layout = c(4, 1),
          auto.key = list(title = "Survived", columns = 2),
          scales = list(x = "free"),
          par.settings=mytheme)

enter image description here

+4
source share
1 answer

Barchart expects separate arguments, not a paired list. I would do something like this:

gbarchart = function(...) {
  args <- as.list(match.call()[-1])
  args$par.settings=mytheme
  do.call(barchart,args)
}

enter image description here

+2
source

All Articles