gt icon indicating copy to clipboard operation
gt copied to clipboard

`summary_rows()` ignores merging pattern after `cols_merge*()` application

Open alex-lauer opened this issue 2 years ago • 1 comments

Prework

  • [ x ] Read and agree to the code of conduct and contributing guidelines.
  • [ x ] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
  • [ x ] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • [ x ] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • [ x ] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • [ x ] Readable: format your code according to the tidyverse style guide.

Description

Hi @rich-iannone,

still a huge fan of your package and grateful for the update of the summary_rows() function. I tried to apply summary rows to two columns and after that, merge them using cols_merge*(), but noticed that the merging pattern was ignored in the summary row. The summary row below only contains the sum of prices in USD, but would ideally include a summary in the form of $105.25 (98.36€).

Reproducible example

library(gt)

pizzaplace |> 
  head() |> 
  dplyr::mutate(
    price_euro = price/1.07
  ) |> 
  gt() |> 
  fmt_currency(
    columns = "price",
    currency = "USD"
  ) |> 
  fmt_currency(
    columns = "price_euro",
    currency = "EUR",
    decimals = 2
  ) |> 
  tab_row_group(
    label = "First 6 records of pizzaplace",
    rows = everything()
  ) |> 
  summary_rows(
    groups = "First 6 records of pizzaplace",
    columns = "price",
    fns = list(label = "Total Sales US Dollar (Euro)", fn = "sum"),
    side = "top"
  ) |> 
  cols_merge_n_pct(
    col_n = "price",
    col_pct = "price_euro"
  ) 

image

Expected result

The summary row should include a summary in the form of the specified merging pattern after one of the cols_merge*() function have been applied.

Session info

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gt_0.8.0.9000   testthat_3.1.5  devtools_2.4.5  usethis_2.1.6   forcats_1.0.0   stringr_1.5.0   dplyr_1.1.0    
 [8] purrr_1.0.1     readr_2.1.3     tidyr_1.3.0     tibble_3.1.8    ggplot2_3.4.0   tidyverse_1.3.2

loaded via a namespace (and not attached):
 [1] bitops_1.0-7        fs_1.6.0            reactable_0.4.3     lubridate_1.9.0     bigD_0.2.0         
 [6] httr_1.4.4          rprojroot_2.0.3     tools_4.2.2         profvis_0.3.7       backports_1.4.1    
[11] utf8_1.2.2          R6_2.5.1            DBI_1.1.3           colorspace_2.1-0    urlchecker_1.0.1   
[16] withr_2.5.0         tidyselect_1.2.0    prettyunits_1.1.1   processx_3.8.0      downlit_0.4.2      
[21] compiler_4.2.2      cli_3.4.1           rvest_1.0.3         xml2_1.3.3          desc_1.4.2         
[26] sass_0.4.5          scales_1.2.1        callr_3.7.3         pkgdown_2.0.6       commonmark_1.8.1   
[31] digest_0.6.31       rmarkdown_2.20      base64enc_0.1-3     pkgconfig_2.0.3     htmltools_0.5.4    
[36] sessioninfo_1.2.2   dbplyr_2.2.1        fastmap_1.1.0       htmlwidgets_1.6.1   rlang_1.0.6        
[41] readxl_1.4.1        rstudioapi_0.14     shiny_1.7.4         generics_0.1.3      jsonlite_1.8.4     
[46] googlesheets4_1.0.1 magrittr_2.0.3      Rcpp_1.0.10         munsell_0.5.0       fansi_1.0.4        
[51] lifecycle_1.0.3     juicyjuice_0.1.0    whisker_0.4         yaml_2.3.7          stringi_1.7.12     
[56] brio_1.1.3          pkgbuild_1.3.1      grid_4.2.2          promises_1.2.0.1    crayon_1.5.2       
[61] miniUI_0.1.1.1      haven_2.5.1         hms_1.1.2           knitr_1.42          ps_1.7.2           
[66] pillar_1.8.1        pkgload_1.3.1       reprex_2.0.2        glue_1.6.2          evaluate_0.20      
[71] remotes_2.4.2       modelr_0.1.9        vctrs_0.5.2         tzdb_0.3.0          httpuv_1.6.8       
[76] cellranger_1.1.0    gtable_0.3.1        assertthat_0.2.1    cachem_1.0.6        xfun_0.36          
[81] mime_0.12           xtable_1.8-4        broom_1.0.1         roxygen2_7.2.3      later_1.3.0        
[86] googledrive_2.0.0   gargle_1.2.1        memoise_2.0.1       timechange_0.1.1    ellipsis_0.3.2     

alex-lauer avatar Feb 13 '23 10:02 alex-lauer

Okay, I think this issue here is the same as what I'm asking about in #1475 and in StackOverflow. I'll just subscribe to this for updates.

sjackson1997 avatar Oct 25 '23 15:10 sjackson1997