# [R] Additional arguments in S3 method produces a warning

Gabor Grothendieck ggrothendieck at gmail.com
Wed Mar 15 22:17:30 CET 2006

```Define extract like this:

extract <- function(e, n, ...) UseMethod("extract")

# test -- no warning
extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)

On 3/15/06, Philippe Grosjean <phgrosjean at sciviews.org> wrote:
> Hello,
> I just notice this:
>  > x <- c(1:4,0:5, 4, 11)
>  > library(pastecs)
>  > 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
> ( ( ( ( (
> ..............................................................
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help