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

Add get_XXX() functions to extract post-processed results (to facilitate QC work) #1441

Closed
dereksonderegger opened this issue Sep 22, 2023 · 0 comments · Fixed by #1449
Closed

Comments

@dereksonderegger
Copy link

At posit::conf(2023), Rich and I talked about this issue and Rich asked me to open a feature request outlining this.

My issue is that while doing Quality Control work for pharmacutical tables, we are often required to show that the table we just produced is identical to one produced under a previous version of the code. Another case is verifying that the table produced by the primary and validation programmer match. However, we can't just compare the guts of the gt object because "there is more than one way to do it."

For example, my primary and validation programmers might have each coded up a table and we need to compare them to show that the displayed outputs are identical:

library(tidyverse)
library(gt)
# data to be shown, all irrational numbers
test_data <- data.frame(
  group1 = c('A','A','B','B'),
  group2 = c('M','F','M','F'),
  value  = c(1/17, 2/17, 3/17, 4/17)
)

### Two different approaches to making a table and doing the rounding
# Do the rounding first, and then pass into gt
gt1 <- 
  test_data |>
  mutate(value = round(value, digits=2) |> paste() ) |>
  pivot_wider( names_from=group2, values_from=value) |>
  gt()
# Let gt do the rounding for me
gt2 <- 
  test_data |>
  pivot_wider( names_from=group2, values_from=value) |>
  gt() |>
  fmt_number(columns=c('M','F'),  decimals=2)
  

# But even though these tables produce the same result, 
# the internal data isn't the same and I can't just do
# Quality Control work by grabbing internal bits because those
# are the pre-processed information
gt1$`_data`
#> # A tibble: 2 × 3
#>   group1 M     F    
#>   <chr>  <chr> <chr>
#> 1 A      0.06  0.12 
#> 2 B      0.18  0.24
gt2$`_data`
#> # A tibble: 2 × 3
#>   group1      M     F
#>   <chr>   <dbl> <dbl>
#> 1 A      0.0588 0.118
#> 2 B      0.176  0.235
Created on 2023-09-22 with [reprex v2.0.2](https://reprex.tidyverse.org/)

Having a set of get_body(), get_column_labels(), etc that capture and extract the post-processed result so that we can write tests against will be massively beneficial for QC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment