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

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jun 26 23:57:55 CEST 2000


Peter Dalgaard BSA <p.dalgaard at 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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list