In rlang what is the difference between 1:10 and !!(1:10)?

library(rlang)

In rlang is this a correct usage?

!!(1:10)
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

str(!!(1:10))
logi [1:10] TRUE TRUE TRUE TRUE TRUE TRUE ...

rep(TRUE,10)
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

str( rep(TRUE,10) )
logi [1:10] TRUE TRUE TRUE TRUE TRUE TRUE ...

These are not identical.

identical(!!(1:10), rep(10, TRUE) )
[1] FALSE
So, what makes them not identical?

Is this what makes them 'not identical'? They both live in the empty environment?

identical( eval_tidy(quo(1:10)), eval_tidy(1:10, env = empty_env()) )
[1] TRUE

Thanks,
Andre

Hi, and welcome to community.rstudio.com!

identical(!!(1:10), rep(10, TRUE) )
[1] FALSE
So, what makes them not identical?

I don't know if you swapped the syntax intentionally in your second-to-last chunk, but if you run identical(!!(1:10), rep(TRUE, 10)), you get

> identical(!!(1:10), rep(TRUE, 10))
[1] TRUE

Notice the arguments inside rep() are TRUE, 10, not 10, TRUE as you have in your post. So in my code, TRUE is being repeated 10 times, which makes it identical to the vector created by !!(1:10).

As for correct usage - I think this gets into quosures, which I'm not seasoned with, so hopefully someone more familiar can chime in here!

By the way, it seems there's some overlap between this post and the other post you've made here:

Are both of these posts seeking the same information?

3 Likes

Thanks kmprioli,

I will re-examine ... and recheck against this ...

In rlang, in quo(!<expression>), evaluation from ! is not occurring right away