Subject: Re: [R] nargs() inside "[.myclass"
From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Tue 27 Jun 2000 - 06:19:54 EST
Message-ID: <x2d7l442l1.fsf@blueberry.kubism.ku.dk>
"Vadim Kutsyy" <vadim@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@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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:24 EST