Carl Witthoft
2008-Jul-25 20:28 UTC
[R] How to pass function argument of same name to internal call?
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?
thanks for any ideas.
Carl
Duncan Murdoch
2008-Jul-25 22:46 UTC
[R] How to pass function argument of same name to internal call?
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