[R] argument names inside a function?

R. Michael Weylandt michael.weylandt at gmail.com
Sat Mar 24 22:20:42 CET 2012


Can you be a little more concrete?

If you want the form of the expression given (rather than its value),
deparse(substitute()) will work:

fnc1 <- function(x){ deparse(substitute(x))}

fnc1(3) # 3

fnc1(x) # "x"

fnc1(x + 4) # "x+4"

If you are passing them through the ... argument, you can coerce that
to a list and use the names() attribute.

If you want to reconstruct the exact call (e.g., for a modelling
function), match.call() will do it.

Hope this helps,
Michael

On Sat, Mar 24, 2012 at 5:04 PM, Ed Siefker <ebs15242 at gmail.com> wrote:
> Is there a way I can get the names of the arguments passed to a
> function from within a function?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list