Is there a way of getting the argument list of a function from within that function? For example, something like f <- function(x, y = 3) { fargs <- getFunctionArgList() print(fargs) ## Should be `alist(x, y = 3)' } Thanks, -roger
> Is there a way of getting the argument list of a function from within > that function? For example, something likeWould formals() work for you here?
Is formals() what you're looking for? Andy> From: Roger D. Peng > > Is there a way of getting the argument list of a function from within > that function? For example, something like > > f <- function(x, y = 3) { > fargs <- getFunctionArgList() > print(fargs) ## Should be `alist(x, y = 3)' > } > > Thanks, > > -roger > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
"Roger D. Peng" <rpeng at jhsph.edu> writes:> Is there a way of getting the argument list of a function from within > that function? For example, something like > > f <- function(x, y = 3) { > fargs <- getFunctionArgList() > print(fargs) ## Should be `alist(x, y = 3)' > }> ffunction(x, y = 3) { fargs <- formals(sys.function()) print(fargs) ## Should be equivalent to `alist(x=, y = 3)' } (Notice a couple of fine points...) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907