Subject: Re: [R] nargs() inside "[.myclass"
From: Robert Gentleman (rgentlem@stat.auckland.ac.nz)
Date: Tue 27 Jun 2000 - 08:42:43 EST
Message-ID: <20000627104243.C21934@stat1.stat.auckland.ac.nz>
On Tue, Jun 27, 2000 at 12:35:57AM +0200, Peter Dalgaard BSA wrote:
> "Vadim Kutsyy" <vadim@kutsyy.com> writes:
>
> > > This does seem to work:
> > >
> > > > "[.myclass"<-function(x,...)
> > > > {n<-nargs();if(n==2&&missing(..1))n<-1;print(n-1)}
> > > > x[]
> > > [1] 0
> > > > x[1]
> > > [1] 1
> > > > x[1,2]
> > > [1] 2
> >
> >
> > It does, thank you. could you explain what ..1 stands for?
>
> It's the first of the "..." arguments.
>
> Some of the things that surround the handling of those are barely
> understood by the maintainers. I've certainly been surprised by having
> "..1" pop up in match.call() output once in a while. I'm not convinced
> that the [] case isn't a bug.
>
> We seem to have managed to code the entire base library without
> referring to ..n arguments a single time, but your example looks like
> it requires it, unless the current behavior is a bug.
I don't think that is true. It is needed for the generic functions
at least at an internal level. Also, I expect that the dispatching
needs a bit of a tidy-up for to handle this; my guess is that nargs
is settled on at time of dispatch and possibly not adjusted once the
method is selected (but I could be wrong and don't have time this week
to do anything about it).
>
>
> Apropos: Here's a little exercise:
>
> > f<-function(...)nargs()
> > f(1)
> [1] 1
> > f()
> [1] 0
> > f(,)
> [1] 2
> > f(,,)
> [1] 3
>
> Now, how do you call f with exactly *one* missing argument?
>
>
> --
> O__ ---- Peter Dalgaard Blegdamsvej 3
> c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-- +-------------------------------------------------------------------------+ | Robert Gentleman phone : (64-9) 3737-599 ext 3946 | | Senior Lecturer fax : (64-9) 3737-018 | | Department of Statistics office : Room 206 Maths/Physics | | University of Auckland email : rgentlem@stat.auckland.ac.nz | +-------------------------------------------------------------------------+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:24 EST