I have a question on the scope of dot-dot-dot arguments. Consider the following function`foo =
foo <- function(x, ...){
require(classInt);
intvl = classIntervals(x, ...);
return(intvl);
}
The function works great for the following calls
x = runif(100, 0, 100);
y1 = foo(x, n = 5, style = 'quantile');
y2 = foo(x, style = 'equal');
But when I try to use the style = 'fixed' argument, which needs a fixedBreaks argument as well, I get
y3 = foo(x, style = 'fixed', fixedBreaks = seq(0, 100, 20))
Error in eval(expr, envir, enclos) : The ... list does not contain 2 elements
Note that the following works perfectly
y5 = classIntervals(x, style = 'fixed', fixedBreaks = seq(0, 100, 20))
I suspsect that this has something to do with scoping rules, but have been unable to put my finger on it. Any help on this would be very much appreciated.
EDIT. I cobbled up a simpler hack that makes it work. I think it is a match.call issue, as the same problem exists for style = 'pretty'. A quick look at the code shows that these are the two styles for which such match.calls are made, so quite likely this is the source of error. Any case, here is my proposed hack
foo2 <- function(x, ...){
require(classInt);
y = list(...); y$var = x;
intvl = do.call('classIntervals', y);
}
y6 = foo2(x, style = 'fixed', fixedBreaks = seq(0, 100, 20))
I think Richie's answer to my question sheds some light on why my earlier code failed to work. But, I still don't understand why this one does.
classIntervals
to me. The author is trying to be fancy withmatch.call
– Gardell