[R] avoiding "multiple actual arguments" in default function	behavior
    Dustin Fife 
    fife.dustin at gmail.com
       
    Wed Feb  5 17:11:15 CET 2014
    
    
  
Suppose I'm creating a function that sets default ylab and xlab behaviors:
plotx = function(x, y, ...){
    plot(x,y, ylab="", xlab="",...)
}
The problem is, on occasion, I actually want to override the defaults
in my function. I would like to do the following:
plotx(1:100, 1:100, xlab="I Don't Work!")
But I get the "multiple actual arguments" error message (which makes
sense). Does anyone know how to set a default (like plotx does), but
allow it to change if the user specifies the same argument via ...?
I tried doing something like this:
plotx = function(x, y, ...){
    args = list(...)
    yl = ifelse(!is.null(args$ylab), args$ylab, "")
    xl = ifelse(!is.null(args$xlab), args$xlab, "")
    plot(x,y, ylab=yl, xlab=xl,...)
}
but got the same error. I then started thinking that maybe I can
remove the ylab and xlab arguments from ..., but I don't know how I'd
do that. Any ideas of how to remove it? Or, is there a better way of
doing this? Thanks!
    
    
More information about the R-help
mailing list