Using multiple ellipses arguments in R

前端 未结 2 543
情深已故
情深已故 2020-12-15 09:19

Is it possible to have multiple ellipsis arguments in an R function? A simplified version of what I\'m trying to do is this:

plotgenerator<-function(x,y,         


        
2条回答
  •  失恋的感觉
    2020-12-15 09:43

    You could so something similar to your second choice if you use do.call, which allows you to pass the arguments to a function as a list. E.g. pass axesarg as a list and then in your function have: do.call(axes,axesarg) etc

    For example:

    outer_fxn <- function(inner_args=list(), ...) {
        do.call(inner_fxn, inner_args)
    }
    
    inner_fxn <- function(...) {
        # do stuff
    }
    
    # function call
    outer_fxn(inner_args=list(a=1, b=2), outer_arg1=3, etc)
    

    In the above, any arguments that should be handled by the inner_fxn ... should be passed in with in the inner_args list. The outer_fxn ... arguments are handled as usual.

提交回复
热议问题