[R] How to pass function argument of same name to internal call?

Duncan Murdoch murdoch at stats.uwo.ca
Sat Jul 26 00:46:30 CEST 2008


On 25/07/2008 4:28 PM, Carl Witthoft wrote:
> I ran across this problem when playing with ccf().
> Its function call is
> 
>  >function (x, y, lag.max = NULL, type = c("correlation", "covariance"),
>      plot = TRUE, na.action = na.fail, ...)
> 
> Internally,  ccf() calls plot(), which digs up plot.acf() whose default 
> style is type='h' .
> 
> I wanted to pass the argument type='l' to the plotting routine, but of 
> course I can't put two arguments named "type" into the ccf() call.
> I made do with the work-around of writing "myccf," with the argument for 
> the acf() call changed to "cortype," but that's ugly.
> 
> Is there a way to "escape" an argument so it gets ignored by the main 
> function and only gets read by the internally-called function?

No.  You should choose "plot=FALSE", save the result, then call plot() 
with your new arg for type.

For example, following the ?ccf example,

 > ccfresult <-  ccf(mdeaths, fdeaths, ylab = "cross-correlation", 
plot=FALSE)
 > plot(ccfresult, type='l')

Duncan Murdoch



More information about the R-help mailing list