Scope of dot-dot-dot Arguments

后端 未结 1 899
遇见更好的自我
遇见更好的自我 2021-01-13 06:40

I have a question on the scope of dot-dot-dot arguments. Consider the following function`foo =

foo <- function(x, ...){
   require(classInt);
   intvl =          


        
相关标签:
1条回答
  • 2021-01-13 07:07

    Inside the foo function, the ellipsis does contain 2 elements. Call this modification to see this.

    foo <- function(x, ...){
       require(classInt);
       print(list(...))
       intvl = classIntervals(x, ...);
       return(intvl);
     }
    

    Once classIntervals is called, the ellipsis changes, since arguments are matched differently. Here's the signature for that function

     classIntervals(var, n, style = "quantile", rtimes = 3, ...,
        intervalClosure = "left", dataPrecision = NULL)
    

    In your call that fails, you have three arguments

    foo(x, style = 'fixed', fixedBreaks = seq(0, 100, 20))
    

    x gets matched up to var through positional matching (i.e., because it's in the first position in the signature in each case).

    style gets matched up to style, via name matching (because they have the same name, duh).

    fixedBreaks can't be matched by position or name so it ends up in the dots.

    Thus the ellipsis contains 1 argument, and the error "The ... list does not contain 2 elements" is correct (if rather silly).


    EDIT: Suggested fix to classIntervals. If you are contacting the author, then suggest replacing lines 42-43

    mc <- match.call(expand.dots = FALSE)
    fixedBreaks <- sort(eval(mc$...$fixedBreaks))
    

    with

    fixedBreaks <- list(...)$fixedBreaks
    

    This is (I think) what they meant, and seemes to solve the silly error message.

    0 讨论(0)
提交回复
热议问题