[R] A question about call()

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jul 24 13:15:55 CEST 2014


On 24/07/2014, 2:41 AM, super wrote:
> The question is as below:
> Exercises
> 1.The following two calls look the same, but are actually different:
>   (a <- call("mean", 1:10))
> #> mean(1:10)

This one creates a call where the first argument is a vector containing
10 elements.

> (b <- call("mean", quote(1:10)))
> #> mean(1:10)

This one creates a call where the first argument is a call to the ":"
function to produce a sequence.

> identical(a, b)
> #> [1] FALSE
> What¡¯s the difference? Which one should you prefer?
> So, how i can figure out this question?  

In this case they deparse the same, but in other cases they wouldn't, e.g.

call("mean", rnorm(10))

appears quite different from

call("mean", quote(rnorm(10)))

The difference is when the evaluation takes place.  Which should you
prefer?  That's up to you.

Duncan Murdoch



More information about the R-help mailing list