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

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jun 26 22:19:54 CEST 2000


"Vadim Kutsyy" <vadim at kutsyy.com> writes:

> I am writing a function to work with class I am defining.  I have a question
> about using nargs() inside of parentheses function.  nargs() shows the same
> for supplying 1 argument, or no arguments at all.  Here is a small example:
> 
> > "[.myclass"<-function(x,...) print(nargs()-1)
> > x<-c(1,2,3)
> > class(x)<-"myclass"
> > x[]
> [1] 1
> > x[1]
> [1] 1
> > x[1,2]
> [1] 2
> 
> how can I determine if there was 1 argument supplied, or none?

Hmm. Interesting. Same thing happens with

> "[.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).

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