kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

collapse_rows() not working

Open kstagaman opened this issue 3 years ago • 4 comments

Using collapse_rows() does nothing, even with the example code from the manual page:

x <- knitr::kable(dt, "html")
collapse_rows(x)

A colleague of mine was able to get it to work in R version 4.0.2, so I wonder if it's a version issue?

Session info:

R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] kableExtra_1.3.4        recipes_0.1.15          RedoControl_0.1.1      
 [4] MASS_7.3-53.1           caret_6.0-86            mblm_0.12.1            
 [7] ggbeeswarm_0.6.0        rcompanion_2.3.27       phyloseqCompanion_0.2.1
[10] GUniFrac_1.1            matrixStats_0.58.0      doParallel_1.0.16      
[13] iterators_1.0.13        foreach_1.5.1           phyloseq_1.32.0        
[16] magrittr_2.0.1          gt_0.2.2                broom_0.7.5            
[19] RColorBrewer_1.1-2      picante_1.8.2           nlme_3.1-152           
[22] vegan_2.5-7             lattice_0.20-41         permute_0.9-5          
[25] ape_5.4-1               usedist_0.4.0           cowplot_1.1.1          
[28] forcats_0.5.1           stringr_1.4.0           dplyr_1.0.5            
[31] purrr_0.3.4             readr_1.4.0             tidyr_1.1.3            
[34] tibble_3.1.0            ggplot2_3.3.3           tidyverse_1.3.0        
[37] data.table_1.14.0       knitr_1.31             

loaded via a namespace (and not attached):
  [1] readxl_1.3.1         backports_1.2.1      Hmisc_4.5-0          systemfonts_1.0.1   
  [5] plyr_1.8.6           igraph_1.2.6         splines_4.0.4        TH.data_1.0-10      
  [9] digest_0.6.27        htmltools_0.5.1.1    rsconnect_0.8.16     fansi_0.4.2         
 [13] checkmate_2.0.0      cluster_2.1.1        Biostrings_2.56.0    modelr_0.1.8        
 [17] gower_0.2.2          svglite_2.0.0        sandwich_3.0-0       prettyunits_1.1.1   
 [21] jpeg_0.1-8.1         colorspace_2.0-0     rvest_1.0.0          haven_2.3.1         
 [25] xfun_0.22            crayon_1.4.1         jsonlite_1.7.2       libcoin_1.0-8       
 [29] Exact_2.1            survival_3.2-7       zoo_1.8-9            glue_1.4.2          
 [33] gtable_0.3.0         ipred_0.9-11         zlibbioc_1.34.0      XVector_0.28.0      
 [37] webshot_0.5.2        Rhdf5lib_1.10.1      BiocGenerics_0.34.0  scales_1.1.1        
 [41] mvtnorm_1.1-1        DBI_1.1.1            Rcpp_1.0.6           viridisLite_0.3.0   
 [45] htmlTable_2.1.0      progress_1.2.2       foreign_0.8-81       Formula_1.2-4       
 [49] stats4_4.0.4         lava_1.6.9           prodlim_2019.11.13   htmlwidgets_1.5.3   
 [53] httr_1.4.2           ellipsis_0.3.1       modeltools_0.2-23    farver_2.1.0        
 [57] pkgconfig_2.0.3      sass_0.3.1           nnet_7.3-15          multcompView_0.1-8  
 [61] dbplyr_2.1.0         utf8_1.1.4           labeling_0.4.2       tidyselect_1.1.0    
 [65] rlang_0.4.10         reshape2_1.4.4       munsell_0.5.0        cellranger_1.1.0    
 [69] tools_4.0.4          cli_2.3.1            generics_0.1.0       ade4_1.7-16         
 [73] evaluate_0.14        EMT_1.1              biomformat_1.16.0    yaml_2.2.1          
 [77] ModelMetrics_1.2.2.2 fs_1.5.0             fitdistrplus_1.1-3   coin_1.4-1          
 [81] rootSolve_1.8.2.1    xml2_1.3.2           compiler_4.0.4       rstudioapi_0.13     
 [85] png_0.1-7            beeswarm_0.3.1       e1071_1.7-4          reprex_1.0.0        
 [89] statmod_1.4.35       bslib_0.2.4          DescTools_0.99.40    stringi_1.5.3       
 [93] highr_0.8            Matrix_1.3-2         commonmark_1.7       multtest_2.44.0     
 [97] vctrs_0.3.6          pillar_1.5.1         lifecycle_1.0.0      BiocManager_1.30.10 
[101] jquerylib_0.1.3      lmtest_0.9-38        lmom_2.8             latticeExtra_0.6-29 
[105] R6_2.5.0             gridExtra_2.3        vipor_0.4.5          IRanges_2.22.2      
[109] gld_2.6.2            codetools_0.2-18     boot_1.3-27          assertthat_0.2.1    
[113] rhdf5_2.32.4         nortest_1.0-4        withr_2.4.1          multcomp_1.4-16     
[117] S4Vectors_0.26.1     mgcv_1.8-34          expm_0.999-6         hms_1.0.0           
[121] grid_4.0.4           rpart_4.1-15         timeDate_3043.102    class_7.3-18        
[125] rmarkdown_2.7        pROC_1.17.0.1        base64enc_0.1-3      Biobase_2.48.0      
[129] lubridate_1.7.10     tinytex_0.30

kstagaman avatar Mar 12 '21 21:03 kstagaman

Is it the same as #595?

haozhu233 avatar Mar 12 '21 22:03 haozhu233

@haozhu233 I confirm this is the same problematic behaviour as in #595: collapse_rows() seems to not alter its input. Meanwhile, this issue has been duplicated in #624 as well.

Upon debugging with the example from #624 (which I can reproduce as well), I presume it's because the mapping_matrix dataframe coming out of the internal collapse_row_matrix() function just looks like the following:

> mapping_matrix
  x1 x2
1  1  1

Its (presumably wrong?) contents are created here, where the inputs (columns, kable_dt) seem still correct:

https://github.com/haozhu233/kableExtra/blob/a6af5c067c2b4ca8317736f4a3e6c0f7db508fef/R/collapse_rows.R#L145-L148

Session info
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.0 (2021-05-18)
 os       Linux Mint 20               
 system   x86_64, linux-gnu           
 ui       X11                         
 language nl_BE:nl                    
 collate  nl_BE.UTF-8                 
 ctype    nl_BE.UTF-8                 
 tz       Europe/Brussels             
 date     2021-06-18                  

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 bslib         0.2.5.1 2021-05-18 [1] CRAN (R 4.1.0)
 cli           2.5.0   2021-04-26 [1] CRAN (R 4.1.0)
 colorspace    2.0-1   2021-05-04 [1] CRAN (R 4.1.0)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
 digest        0.6.27  2020-10-24 [1] CRAN (R 4.1.0)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
 fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
 highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
 htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.1.0)
 httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
 jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.1.0)
 jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.1.0)
 kableExtra  * 1.3.4   2021-02-20 [1] CRAN (R 4.1.0)
 knitr         1.33    2021-04-24 [1] CRAN (R 4.1.0)
 lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.1.0)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
 pillar        1.6.1   2021-05-16 [1] CRAN (R 4.1.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
 R6            2.5.0   2020-10-28 [1] CRAN (R 4.1.0)
 rlang         0.4.11  2021-04-30 [1] CRAN (R 4.1.0)
 rmarkdown     2.8     2021-05-07 [1] CRAN (R 4.1.0)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
 rvest         1.0.0   2021-03-09 [1] CRAN (R 4.1.0)
 sass          0.4.0   2021-05-12 [1] CRAN (R 4.1.0)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
 stringi       1.6.2   2021-05-17 [1] CRAN (R 4.1.0)
 stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
 svglite       2.0.0   2021-02-20 [1] CRAN (R 4.1.0)
 systemfonts   1.0.2   2021-05-11 [1] CRAN (R 4.1.0)
 tibble        3.1.2   2021-05-16 [1] CRAN (R 4.1.0)
 utf8          1.2.1   2021-03-12 [1] CRAN (R 4.1.0)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
 viridisLite   0.4.0   2021-04-13 [1] CRAN (R 4.1.0)
 webshot       0.5.2   2019-11-22 [1] CRAN (R 4.1.0)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.1.0)
 xfun          0.23    2021-05-15 [1] CRAN (R 4.1.0)
 xml2          1.3.2   2020-04-23 [1] CRAN (R 4.1.0)

[1] /home/floris/lib/R/library
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

florisvdh avatar Jun 18 '21 13:06 florisvdh

As @jacpete comments in https://github.com/haozhu233/kableExtra/issues/595#issuecomment-906646896 and https://github.com/haozhu233/kableExtra/issues/624#issuecomment-906640656, the problem is fixed in the GitHub development version, but not yet on CRAN. This issue seems a duplicate.

florisvdh avatar Aug 27 '21 09:08 florisvdh

I confirm this is working on dev version. Does anybody know if a new CRAN version is planned?

py-b avatar Oct 26 '21 12:10 py-b