Ellipse extension in nested functions: Error "..3 is used in the wrong context, no ... look in"

I have the following code snippet:

require(lattice)
f.barchart <- function(...) {
    barchart(...,
        panel = function(x, y, ...) {
            panel.barchart(x, y, ...)
        }
    )
}

x <- data.frame(a = c(1,1,2,2), b = c(1,2,3,4), c = c(1,2,2,1))
f.barchart(a ~ b, data = x, groups = c)

As a result, the following error occurs:

..3 used in an incorrect context, no ... to look in

When I use the following definition:

f.barchart <- function(...) {
    substitute(barchart(...,
        panel = function(x, y, ...) {
            panel.barchart(x, y, ...)
        }
    ))
}

I get:

barchart(a ~ b, data = x, groups = c,
    panel = function(x, y, ...) {
        panel.barchart(x, y, a ~ b, data = x, groups = c)
    })

I am not sure if this is the cause of the error above, but that would mean that the ellipsis in panel.barchart is erroneously expanded using the contents of the arguments given by f.barchart and not the panel function.

Is there any way to avoid this problem? How can I make the function Work?

+3
source share
1 answer

As far as I understand, this is not due to the nested ... but because of the first ... in the barchart. So even this does not work:

f.barchart <- function(...) {
    barchart(...)
}

x <- data.frame(a = c(1,1,2,2), b = c(1,2,3,4), d = c(1,2,2,1))
print(f.barchart(a ~ b, data = x, groups = d))

, , ... , barchart . , , . - :

f.barchart <- function(...) {
  cl<-match.call()
  cl$panel=function(x, y, ...) {
            panel.barchart(x, y, ...)
          }
  cl[[1]]=barchart
  eval(cl)
}

f.barchart match.call, , , , barchart, . , , , f.barchart, barchart.

+7

Source: https://habr.com/ru/post/1733317/


All Articles