From p.dalgaard@biostat.ku.dk  Tue Jul 25 12:25:57 2000
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 25 Jul 2000 13:25:57 +0200
Subject: [Rd] number of parameters of a function.
In-Reply-To: Duncan Temple Lang's message of "Tue, 25 Jul 2000 07:12:09 -0400 (EDT)"
References: <200007251112.HAA06228@jessie.research.bell-labs.com>
Message-ID: <x24s5emoxm.fsf@blueberry.kubism.ku.dk>

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


[Rd] number of parameters of a function.
Peter Dalgaard BSA