From andy_liaw at merck.com  Wed Feb  1 23:10:46 2006
From: andy_liaw at merck.com (Liaw, Andy)
Date: Wed, 1 Feb 2006 17:10:46 -0500
Subject: [Rd] Retrieving an unevaluated argument
Message-ID: <39B6DDB9048D0F4DAD42CB26AAFF0AFAFED7AC@usctmx1106.merck.com>

Why isn't substitute(x, parent.frame()) enough?  parse(deparse()) seems
redundant...

Andy

From: hadley wickham
> 
> I'm trying to retrieve an unevalated argument (a list in particular). 
> I can do this easily when I call the function directly:
> 
> a1 <- function(x) match.call()$x
> 
> > a1(list(y=x^2))
> list(y = x^2)
> 
> But when the function is called by another function, it gets trickier
> 
> b <- function(x, f) f(x)
> 
> > b(list(x^2), a1)
> x
> 
> The best I've been able to do is:
> 
> a2 <- function(x) parse(text=deparse(substitute(x, 
> parent.frame())))[[1]]
> 
> > b(list(x^2), a2)
> list(x^2)
> 
> But I'm sure there must be a better way!
> 
> Hadley
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
>



[Rd] Retrieving an unevaluated argument
Liaw, Andy