[Rd] number of parameters of a function.

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
25 Jul 2000 13:25:57 +0200


Duncan Temple Lang <duncan@research.bell-labs.com> writes:

>  Is there a way to programmatically determine how many arguments a function
> accepts? In S, one can compute this as 
>           length(theFunction) - 1
> and determine the parameter names  as
>           names(theFunction)
> due to the representation of functions.
> 
> (Just in case anyone is thinking of nargs(),  that is just for
> particular calls and does not concern itself with the function
> definition.)

Like this:

> length(formals(scan))
[1] 13
> names(formals(scan))
 [1] "file"        "what"        "nmax"        "n"           "sep"        
 [6] "quote"       "dec"         "skip"        "nlines"      "na.strings" 
[11] "flush"       "strip.white" "quiet"      


-- 
   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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._