[R] get arguments passed to function inside a function

Greg Snow Greg.Snow at imail.org
Thu Sep 1 22:51:42 CEST 2011


The sys.call or match.call functions may be what you are looking for:

> tmpfun <- function(x,y,z,...) {
+ as.list( sys.call() )
+ }
> 
> tmpfun( x=5, w=3, 1:10 )
[[1]]
tmpfun

$x
[1] 5

$w
[1] 3

[[4]]
1:10

> tmpfun2 <- function(x,y,z,...) {
+ as.list( match.call() )
+ }
> tmpfun2( x=5, w=3, 1:10 )
[[1]]
tmpfun2

$x
[1] 5

$y
1:10

$w
[1] 3

>

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jannis
> Sent: Thursday, September 01, 2011 9:14 AM
> To: r-help at r-project.org
> Subject: [R] get arguments passed to function inside a function
> 
> Dear list,
> 
> 
> I am wondering whether there is an (easy) way to access all arguments
> and their values passed to a function inside this function and (for
> example) store them in a list object?
> 
> I could imagine using ls() inside this function and then looping
> through all names and assigning list entries with the values of the
> respective objects but I could imagine that there is already something
> ready made in R to achieve this.
> 
> Does anybody have an idea?
> 
> Thanks
> Jannis
> 
> 
> ______________________________________________
> 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