[R] persp(), scatterplot3d(), "..." argument
Jari Oksanen
jarioksa at sun3.oulu.fi
Wed Oct 27 10:38:08 CEST 2004
On Wed, 2004-10-27 at 11:11, Uwe Ligges wrote:
> Jari Oksanen wrote:
>
> > On Wed, 2004-10-27 at 10:04, Uwe Ligges wrote:
> >
> >
> > This is a larger problem if
> > 1. one of the underlying functions does not have "..."
> > 2. you want to relay arguments to two or more underlying functions, and
> > 3. you don't want to list all possible arguments in your function
> > definition, since it is long enough already.
> >
> > The solution is still there, but it is (black) magic. For instance,
> > 'arrows' does not have "...", so you must add them with this magical
> > mystery string:
> >
> > formals(arrows) <- c(formals(arrows), alist(... = ))
>
>
> You don't need it for simple things like:
>
> foo <- function(...){
> plot(1:10)
> arrows(1,1,7,7,...)
> }
>
> foo(lwd=5) # works!
>
That's why I had point 2 above: it really would work with simpler
things. However, the following may fail:
> parrow <-
function (x, y, ...)
{
plot(x, y, ...)
arrows(0, 0, x, y, ...)
invisible()
}
> parrow(runif(10), runif(10), col="red") # works
> parrow(runif(10), runif(10), col="red", pch=16)
Error in arrows(0, 0, x, y, ...) : unused argument(s) (pch ...)
Adding formals would help.
>
> As always, useful patches are welcome.
>
I don't know if this counts as a "useful patch", but it is patch anyway:
diff -u2r old/arrows.R new/arrows.R
--- old/arrows.R 2004-10-27 11:32:25.000000000 +0300
+++ new/arrows.R 2004-10-27 11:32:53.000000000 +0300
@@ -1,5 +1,5 @@
"arrows" <-
function (x0, y0, x1, y1, length = 0.25, angle = 30, code = 2,
- col = par("fg"), lty = NULL, lwd = par("lwd"), xpd = NULL)
+ col = par("fg"), lty = NULL, lwd = par("lwd"), xpd = NULL, ...)
{
.Internal(arrows(x0, y0, x1, y1, length = length, angle = angle,
cheers, jari oksanen
--
J.Oksanen, Oulu, Finland.
"Object-oriented programming is an exceptionally bad idea which could
only have originated in California." E. Dijkstra
More information about the R-help
mailing list