Show used columns in `col_vals_expr()`
Summary
This PR aims to have col_vals_expr() show columns used in expr in the agent report. Example inspired by fn docs:
tbl <-
dplyr::tibble(
a = c(1, 2, 1, 7, 8, 6),
b = c(0, 0, 0, 1, 1, 1),
c = c(0.5, 0.3, 0.8, 1.4, 1.9, 1.2),
)
c <- 1
tbl %>%
create_agent() %>%
col_vals_expr(expr = ~ a %% 1 == 0) %>%
col_vals_expr(expr = ~ case_when(
b == 0 ~ a %>% between(0, 5) & c < 1,
b == 1 ~ a > 5 & c >= 1
)) %>%
col_vals_expr(expr(.data$a + b == !!c)) %>%
col_vals_expr(expr = ~ a + d > 0) %>%
interrogate()
This is a draft because it needs more tests.
Related GitHub Issues and PRs
- Ref: #477
Checklist
- [ ] I understand and agree to the Code of Conduct.
- [ ] I have listed any major changes in the NEWS.
- [ ] I have added
testthatunit tests totests/testthatfor any new functionality.
Apparently {covr} injects its own expressions into even quote()/expr()-ed code - https://github.com/r-lib/covr/issues/381. This unfortunately interferes with the expr parsing process and makes the new feature impossible to test on the test-coverage/codecov GHA.
I'm trying to find a good way around this but the good thing is that this feature is purely a convenience of display in the agent report, so currently I have it failing gracefully in case of parsing errors (falls back to showing nothing for columns) and I'll think more about what I can do w.r.t. including it in (automated) tests.
@rich-iannone I think I finally managed to get this working! The key was simply ensuring parse(..., keep.source = TRUE) - it's FALSE in non-interactive mode which was causing failures in GHA
This is amazing, thank you for figuring this out!