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.) Thanks, Duncan -- _______________________________________________________________ Duncan Temple Lang duncan@research.bell-labs.com Bell Labs, Lucent Technologies office: (908)582-3217 700 Mountain Avenue, Room 2C-259 fax: (908)582-3340 Murray Hill, NJ 07974-2070 http://cm.bell-labs.com/stat/duncan "Languages shape the way we think, and determine what we can think about." Benjamin Whorf -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 25 Jul 2000, Duncan Temple Lang wrote:> > 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.length(formals(theFunction)) Something similar works in S-PLUS 5.x: length(functionArgs(theFunction)) as I guess Duncan knows. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._