Re: [R] nargs() inside "[.myclass"

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [R] nargs() inside "[.myclass"
From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Tue 27 Jun 2000 - 07:57:55 EST


Message-ID: <x2bt0ot89o.fsf@blueberry.kubism.ku.dk>

Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

> > "[.myclass"<-function(x,...)
> > {n<-nargs();print(n-1);m<-match.call();print(m)}
> > x[]
> [1] 1
> [.myclass(x = x, )
> > x[1]
> [1] 1
> [.myclass(x = x, 1)
> > x[1,2]
> [1] 2
> [.myclass(x = x, 1, 2)
>
> Doesn't look quite right... The problem sees to be that in the x[]
> case one passes two arguments of which one is missing (note that f(x)
> and f(x,) is not quite the same thing).

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

-- 
   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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:24 EST