pointblank icon indicating copy to clipboard operation
pointblank copied to clipboard

Show used columns in `col_vals_expr()`

Open yjunechoe opened this issue 2 years ago • 1 comments

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()

image

This is a draft because it needs more tests.

Related GitHub Issues and PRs

  • Ref: #477

Checklist

yjunechoe avatar Nov 05 '23 16:11 yjunechoe

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.

yjunechoe avatar Nov 05 '23 20:11 yjunechoe

@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

yjunechoe avatar Jun 09 '24 09:06 yjunechoe

This is amazing, thank you for figuring this out!

rich-iannone avatar Jun 09 '24 10:06 rich-iannone