From h.wickham at gmail.com  Thu May  1 23:39:43 2014
From: h.wickham at gmail.com (Hadley Wickham)
Date: Thu, 1 May 2014 16:39:43 -0500
Subject: [Rd] How to test if an object/argument is "parse tree" -
 without evaluating it?
In-Reply-To: <CAJXgQP0Ze2sAMbNRtVKYBNSBQmN4cXZMPPPnUOnnyvtBRnSH+A@mail.gmail.com>
References: <CAFDcVCRpqqPkhFhaNpqe3ye-jo-8sWOODShKHneonTSB7m5Uvg@mail.gmail.com>
	<5362B47E.8010801@gmail.com>
	<CAJXgQP0Ze2sAMbNRtVKYBNSBQmN4cXZMPPPnUOnnyvtBRnSH+A@mail.gmail.com>
Message-ID: <CABdHhvFsgFDm45-uYWtYAg_rS4XGekQMdrUgWJs_K7CO+AC7Kw@mail.gmail.com>

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/



[Rd] How to test if an object/argument is "parse tree" - without evaluating it?
Hadley Wickham