msm1089
msm1089

Reputation: 1504

Proper way to use rlang::.data pronoun with dplyr

I'm sure the below code used to work, but now it throws an error. Is this a bug? filter is a data-masking verb, but the message seems to suggest it is not. The documentation for dplyr recommends this pattern when using dplyr in packages.

mtcars %>% dplyr::filter(rlang::.data$mpg > 10)
Error: Can't subset `.data` outside of a data mask context.

While trying to work around this, I found that the same issue exists for mutate. Am I making some mistake or is .data broken?

mtcars %>% dplyr::mutate(mpg = rlang::.data$mpg)
Error: Can't subset `.data` outside of a data mask context.

Upvotes: 1

Views: 68

Answers (1)

msm1089
msm1089

Reputation: 1504

Turned out the issue was namespacing with rlang! It is a bit weird, since dplyr is not re-exporting .data (for v1.1.4, I think it used to).

Upvotes: 0

Related Questions