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

Allow functions and formulas with non-call RHS in across #288

Merged
merged 8 commits into from
Aug 30, 2021

Conversation

eutwt
Copy link
Collaborator

@eutwt eutwt commented Aug 27, 2021

This PR does two things. Included together since they're both expanding possible across inputs and both pretty small changes.

  1. Skips dt_squash_call for formulas whose RHS is not a call, allowing such formulas in across
  1. Allows anonymous non-formula functions in across

I could separate these if needed (and if there's interest in accepting either of them)

library(dplyr, warn.conflicts = FALSE)
library(dtplyr, warn.conflicts = FALSE)

lazy_dt(data.frame(a = 1, b = 2)) %>% 
  mutate(across(a, ~ b)) %>% 
  as_tibble()
#> # A tibble: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     2     2

lazy_dt(data.frame(a = 1, b = 2)) %>% 
  mutate(across(a:b, function(x) x + 1)) %>% 
  as_tibble()
#> # A tibble: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     2     3

Created on 2021-08-27 by the reprex package (v2.0.1)

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — just one question and can you please add a bullet to the top of NEWS.md? It should briefly describe the change and end with (@yourname, #issuenumber).


expect_equal(
capture_across(dt, across(a, function(x) log(x))),
quo_squash(list(a = call2(function(x) log(x), quote(a))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you construct the expected value a little more directly? I don't remember what quo_squash() does off the top of my head.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it was a mistake to have it there, thanks for catching that. In this case it wasn't doing anything. I've removed it.

@eutwt
Copy link
Collaborator Author

eutwt commented Aug 30, 2021

Should be all set now

@hadley hadley merged commit 039f1bc into tidyverse:master Aug 30, 2021
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

Successfully merging this pull request may close these issues.

2 participants