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

Cannot test grouped data #68

Closed
kinto-b opened this issue May 19, 2022 · 5 comments
Closed

Cannot test grouped data #68

kinto-b opened this issue May 19, 2022 · 5 comments

Comments

@kinto-b
Copy link
Contributor

kinto-b commented May 19, 2022

library(testdat)
library(dplyr)

mtcars %>% group_by(am) %>% expect_values(vs, 0:1, data = .)
#> Adding missing grouping variables: `am`
#> Error: Problem with `mutate()` input `..1`.
#> i `..1 = across(everything(), ~ifelse(flt$.cond, ., NA))`.
#> i `..1` must be size 19 or 1, not 32.
#> i The error occurred in group 1: am = 0.

Created on 2022-05-20 by the reprex package (v2.0.1)

@TiO2
Copy link

TiO2 commented Nov 2, 2022

To apply function to dplyr grouped data, the documentation has it https://dplyr.tidyverse.org/reference/group_map.html

Following seem working ok:

mtcars %>%
group_by(am)%>%
group_map( ~ test_that("range between 0 and 1", {
expect_values(vs, 0:1, data = .x)
}) )

both passed

mtcars %>%
group_by(am)%>%
group_map( ~ test_that("range between 0 and 1", {
expect_values(vs, 0:0.5, data = .x)
}) )

Error in reporter$stop_if_needed() : Test failed

@kinto-b
Copy link
Contributor Author

kinto-b commented Nov 8, 2022

Thanks @TiO2. I think it's probably still worth refactoring to natively support grouped data. It's just a quirk of the implementation on the back-end that's preventing it from working

@gorcha
Copy link
Collaborator

gorcha commented Nov 14, 2022

Hey @kinto-b,

I'm leaning towards removing/ignoring groups if a grouped tibble is used (so they don't throw an error), but I can't really see a need for any further support.

The way I see it our focus is on testing data sets as a whole. If tests need to be run separately on each group then the grouping can be done outside of the test functions like in the example from @TiO2 above.

Happy to be convinced otherwise though!

@kinto-b
Copy link
Contributor Author

kinto-b commented Nov 14, 2022

@gorcha Oh no I agree. I really just meant fixing the bug that's preventing grouped data from being passed through. I can't really think of a good use-case for group-wise testing

@gorcha
Copy link
Collaborator

gorcha commented Nov 14, 2022

OK cool, easy! 🙂

@gorcha gorcha closed this as completed in 8f38bbd Jan 19, 2023
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

3 participants