r - Get a list of all function parameters from inside the function -
is there way all function parameters within function?
match.call() doesn't return parameters defaults set not overridden. example:
xf <- function (a, b="hi", c=true) { print(as.list(match.call(expand.dots=false))) } >xf(3) [[1]] xf $a [1] 3 i writing package function calls existing function, want able set defaults not on existing function. (i planning on using list match.call, passing other function do.call , returning result.
update: interesting issue relates s3 methods. created new s3 method, , used @ferdinand.kraft's answer. as.list(environment(), all.names=true) all.names argument keeps names starting . in list. turns out the method dispatch adds several arguments function environment, including .generic .class .method , several others. cause problems if pass these on function in do.call. 1 of other answers may better around solution, simplicity of as.list(environment()).
you can return environment @ beginning of function:
xf <- function (a, b="hi", c=true) { as.list(environment(), all=true) } result:
> xf(a=1) $a [1] 1 $b [1] "hi" $c [1] true
Comments
Post a Comment