[R] What is the difference between expression and quote whenusedwith eval()?
William Dunlap
wdunlap at tibco.com
Fri Feb 19 20:28:49 CET 2010
I think of quote(something) as being equivalent
to expression(something)[[1]].
eval() goes through the outermost expression layer
> eval(expression(expression(noSuchFunction(noSuchValue))))
expression(noSuchFunction(noSuchValue))
> eval(eval(expression(expression(noSuchFunction(noSuchValue)))))
Error in eval(expr, envir, enclos) :
could not find function "noSuchFunction"
so I don't think you will ever see a difference between
eval(quote(something)) and eval(expression(something)).
Any low level function other than eval will treat them
differently.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Bert Gunter
> Sent: Friday, February 19, 2010 11:10 AM
> To: 'blue sky'; r-help at stat.math.ethz.ch
> Subject: Re: [R] What is the difference between expression
> and quote whenusedwith eval()?
>
> > as.list(expression( 2*3))
> [[1]]
> 2 * 3
>
> > as.list(quote( 2*3))
> [[1]]
> `*`
>
> [[2]]
> [1] 2
>
> [[3]]
> [1] 3
>
> > identical(as.list(expression( 2*3))[[1]],quote(2*3))
> [1] TRUE
>
> expression() wraps the call into an expression object (as
> pointed out to me
> by Gabor Grothendieck).
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On
> Behalf Of blue sky
> Sent: Friday, February 19, 2010 9:43 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] What is the difference between expression and quote when
> usedwith eval()?
>
> I made the following example to see what are the difference between
> expression and quote. But I don't see any difference when they are
> used with eval()? Could somebody let me know what the difference is
> between expression and quote?
>
>
> expr=expression(2*3)
> quo=quote(2*3)
>
> eval(expr)
> str(expr)
> class(expr)
> typeof(expr)
> mode(expr)
> attributes(expr)
>
> eval(quo)
> str(quo)
> class(quo)
> typeof(quo)
> mode(quo)
> attributes(quo)
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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