[R] Additional arguments in S3 method produces a warning
Philippe Grosjean
phgrosjean at sciviews.org
Wed Mar 15 21:57:14 CET 2006
Hello,
I just notice this:
> x <- c(1:4,0:5, 4, 11)
> library(pastecs)
Loading required package: boot
> tp <- turnpoints(x)
> extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)
[1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
FALSE
Warning message:
arguments after the first two are ignored in: UseMethod("extract", e, n,
...)
> extract(tp)
[1] 0 0 0 1 -1 0 0 0 0 1 -1 0
Warning message:
arguments after the first two are ignored in: UseMethod("extract", e, n,
...)
My extract.turnpoints() function produces warnings. I can easily spot
the origin of this warning:
> extract
function (e, n, ...)
UseMethod("extract", e, n, ...)
> extract.turnpoints
function (e, n, no.tp = 0, peak = 1, pit = -1, ...)
{
if (missing(n))
n <- length(e)
res <- rep(no.tp, length.out = e$n)
res[e$pos[e$peaks]] <- peak
res[e$pos[e$pits]] <- pit
if (n < length(res) & n > 0)
res <- res[1:n]
res
}
This is because my extract.turnpoints() method defines more arguments
than 'e' and 'n' in the generic function. However,
1) I though that the '...' argument in S3 generic function was there to
allow defining/passing additional arguments in/to S3 methods. Is this
correct? If yes, why the warning?
2) Despite the warning says arguments after the first two are ignored,
this appears not to be the case: in this example, 'no.tp', 'peak' and
'pit' arguments are taken into account, as you can see (different
behaviour if you give other values to them).
I am a little bit lost. Could someone help me, please.
Best,
Philippe Grosjean
--
..............................................<°}))><........
) ) ) ) )
( ( ( ( ( Prof. Philippe Grosjean
) ) ) ) )
( ( ( ( ( Numerical Ecology of Aquatic Systems
) ) ) ) ) Mons-Hainaut University, Pentagone (3D08)
( ( ( ( ( Academie Universitaire Wallonie-Bruxelles
) ) ) ) ) 8, av du Champ de Mars, 7000 Mons, Belgium
( ( ( ( (
) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
( ( ( ( ( email: Philippe.Grosjean at umh.ac.be
) ) ) ) )
( ( ( ( ( web: http://www.umh.ac.be/~econum
) ) ) ) ) http://www.sciviews.org
( ( ( ( (
..............................................................
More information about the R-help
mailing list