[R] returning argument names
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Feb 18 00:00:19 CET 2003
Michael.Scroggie at nre.vic.gov.au writes:
> Dear r-list folks,
> I have a problem which has been bugging me for a while now and I was hoping
> someone out there might be able to help.
> If I have a user-defined function with an indeterminate number of
> arguments, using the well-known "..." construct, how can I get the
> function to return the names of the items which were the arguments of the
> function as part of the function's output? This is easily done where there
> is a fixed number of arguments: e.g:
> How can I produce a similar results from a function where there is an indeterminate number of arguments i.e:
> Any suggestions or solutions would be much appreciated.
match.call() is your friend. E.g.
f <- function(...) sapply(as.list(match.call())[-1], deparse)
actually, as.list is superfluous:
f <- function(...) sapply(match.call()[-1], deparse)
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
More information about the R-help