[Rd] How to test if an object/argument is "parse tree" - without evaluating it?
Hadley Wickham
h.wickham at gmail.com
Thu May 1 23:39:43 CEST 2014
On Thu, May 1, 2014 at 4:08 PM, Kevin Ushey <kevinushey at gmail.com> wrote:
> Henrik,
>
> If I understand correctly, you want something along the lines of
> (following your example):
>
> foo <- function(expr) {
> if (!is.language(expr)) substitute(expr)
> else expr
> }
>
> ## first example
> expr0 <- foo({ x <- 1 })
> expr1 <- foo(expr0)
> stopifnot(identical(expr1, expr0))
>
> ## second
> expr2 <- foo(foo(foo(foo(expr0))))
> stopifnot(identical(expr2, expr0))
Unfortunately this won't work in general because is.language evaluates expr:
foo(stop("Uh oh!"))
In general, I'm with Bill Dunlap - you're better off being explicit
with formulas.
Hadley
--
http://had.co.nz/
More information about the R-devel
mailing list