Thank you all for great feedback - very helpful.
They view was great half way up the tree, but I'll add this one to "It
may be possible, but don't do it. Rethink what you're doing".
Hadley touches on this in his write up
[http://adv-r.had.co.nz/Computing-on-the-language.html#calling-from-another-
My take would be that this is barking up the wrong tree. If you want to pass
expressions in a way that a function can recognize, use formulas or expression
objects.
One problem is that pretty much every unevaluated argument is a "parse tree".
The only other thing it can be is a constant object
On Thu, May 1, 2014 at 4:08 PM, Kevin Ushey 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
> ex
> This may have been asked before, but is there an elegant way to check
> whether an variable/argument passed to a function is a "parse tree"
> for an (unevaluated) expression or not, *without* evaluating it if
> not?
I doubt it.
Some packages say that if the argument is a formula then its right
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(ex
On 01/05/2014, 4:39 PM, Henrik Bengtsson wrote:
This may have been asked before, but is there an elegant way to check
whether an variable/argument passed to a function is a "parse tree"
for an (unevaluated) expression or not, *without* evaluating it if
not?
"Parse tree" isn't R terminology. Co
This may have been asked before, but is there an elegant way to check
whether an variable/argument passed to a function is a "parse tree"
for an (unevaluated) expression or not, *without* evaluating it if
not?
Currently, I do various rather ad hoc eval()+substitute() tricks for
this that most like