Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support for .data pronoun #56

Closed
karldw opened this issue Jan 5, 2018 · 5 comments
Closed

Feature request: support for .data pronoun #56

karldw opened this issue Jan 5, 2018 · 5 comments

Comments

@karldw
Copy link
Contributor

karldw commented Jan 5, 2018

Thanks for the great package!

I'm wondering if you'd consider adding support for the .data and .env pronouns from the tidyverse's new tidyeval framework. (.data says "look in the dataframe for the column" while .env says something like "look in the environment for the value")

See the dplyr programming vignette has some background.) I think the rlang::eval_tidy function will be key here.

Here's a demo:

library(rlang)
library(assertr)

mtcars %>% verify(mpg > 30)  # verify works!
#> verification [mpg > 30] failed! (28 failures)

mgp <- 40
mtcars %>% verify(mgp > 30)  # fat fingers :(
# No error because mgp exists elsewhere

# I'd like to write:
mtcars %>% verify(.data$mpg > 30)
# and 
mtcars %>% verify(.data$mpg > .env$mgp)


# How it works in dplyr:
mtcars %>% dplyr::mutate(x = mgp)  # no error, but mgp always 40

# but if we're careful, we get an error
mtcars %>% dplyr::mutate(x = .data$mgp)
#> Error in mutate_impl(.data, dots) : 
#>  Evaluation error: Column `mgp`: not found in data.

@karldw
Copy link
Contributor Author

karldw commented Jan 5, 2018

Hmm, it seems that .env might not be helpful because of the way %>% works. See r-lib/rlang#339 for details.
I think .data might still be useful.

@karldw karldw changed the title Feature request: support for .data and .env pronouns Feature request: support for .data pronoun Jan 5, 2018
@tonyfischetti
Copy link
Owner

Haha, I'll have to read the vignette you posted.
I'll check back in when I've read it

Thanks for the suggestion :)

@tonyfischetti
Copy link
Owner

Hi!
I'd definitely consider adding this. I see you're a contributor to rlang, would you like to submit a pull request? I feel like I don't understand rlang nearly as well as you.

@karldw
Copy link
Contributor Author

karldw commented Feb 23, 2018

Sure! It will be a bit before I'm able to write the PR, but it's on my list.

@tonyfischetti
Copy link
Owner

Great! Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants