Hi,
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)
Which results in the following error being thrown:
..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'm not sure if this is the cause of above error but this would mean
that the ellipsis in panel.barchart gets wrongly expanded with the
contents of the arguments given to f.barchart and not the panel
function.
Is there a way to avoid this problem? How can I make the function
work?
I use R 2.10.1 @ win32.
Regards,
Tom
ellipsis-related error: used in an incorrect context, no ... to look in
3 messages · Leon, Felix Andrews
2 days later
Does nobody have an advice concerning that problem? If it is a FAQ, I'd appreciate a pointer to a discussion of this issue. With the docs accessible to me, I wasn't able to solve that problem.
? ? 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)
Which results in the following error being thrown:
? ? ..3 used in an incorrect context, no ... to look in
Regards, Tom
The problem is related to the processing of the 'groups' argument,
which is subject to non-standard evaluation. The groups argument is
substitute()d and evaluated in a special context ('data' etc). But
this gets messed up if you are not passing the symbol directly. The
work-around is to rewrite the call inside f.barchart (as is done in,
for example, lattice:::barchart.formula)
Example:
f.barchart <- function(...) {
ccall <- match.call()
ccall[[1]] <- quote(barchart)
ccall$panel <- function(x, y, ...) {
panel.barchart(x, y, ...)
}
eval.parent(ccall)
}
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)
It is also good practice to update the $call component of the trellis
object to reflect your high-level function:
ans <- eval.parent(ccall)
ans$call <- match.call()
ans
On 19 February 2010 19:58, lith <minilith at gmail.com> wrote:
Does nobody have an advice concerning that problem? If it is a FAQ, I'd appreciate a pointer to a discussion of this issue. With the docs accessible to me, I wasn't able to solve that problem.
? ? 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)
Which results in the following error being thrown:
? ? ..3 used in an incorrect context, no ... to look in
Regards, Tom
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Felix Andrews / ??? Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andrews at anu.edu.au CRICOS Provider No. 00120C