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

Vadim Kutsyy vkutsyy at yahoo.com
Mon Jun 26 23:48:49 CEST 2000


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

exactly, but if you don't pass anything at all, you can not even test if
something is missing, ie:

> "[.myclass"<-function(x,...) {n<-nargs();print(n-1);print(list(...))}
> x<-c(1,2,3)
> class(x)<-"myclass"
> x[1]
[1] 1
[[1]]
[1] 1

> x[]
[1] 1
Error in print(list(...)) : Argument is missing, with no default


As a result, I can not figure out way to see if it was pass as x[] or x[1].
It is possible to differentiate x[1,] vs x[1,2].

Any idea, how to get around it?


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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