davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
554 stars 79 forks source link

Correct decimal rounding stopped working in a huxreg -> flextable #365

Closed astraetech closed 2 years ago

astraetech commented 2 years ago

Hi,

An hour ago, the decimals stopped rounding up in a huxreg() to flextable pipeline. They worked perfectly well before, so must be some setting or a conflict somewhere? Restarting R session didnt help. Using colformat_double(digits=3) didn't do anything (not sure if it's supposed to as I'm just starting with flextable).

Reprex:


library(huxtable)
library(flextable)
lm(formula=mpg~cyl+hp, mtcars) %>% huxreg() %>% as_flextable()

image

Here is the output from huxreg only: image

Thank you for any help!

SessionInfo

R version 4.1.1 (2021-08-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages: [1] threejs_0.3.4 igraph_1.2.8
[3] fixest_0.10.1 multidplyr_0.1.0.9000
[5] binance_0.0.4 binancer_1.1.0
[7] rameritrade_0.1.5 crypto_1.1.3
[9] rvest_1.0.2 censusapi_0.7.2
[11] rgdax_1.2.1 httr_1.4.2
[13] RCurl_1.98-1.5 jsonlite_1.7.2
[15] digest_0.6.29 hpiR_0.3.4
[17] modelsummary_0.9.2.9000 Rfast_2.0.3
[19] RcppZiggurat_0.1.6 Rcpp_1.0.7
[21] collapse_1.6.5 rcanvas_0.0.0.9001
[23] reticulate_1.22-9000 DataEditR_0.1.4
[25] texreg_1.38.2 laviz_0.0.0.9000
[27] qs_0.25.1 fst_0.9.4
[29] pointr_0.2.0 duckdb_0.3.0
[31] RPostgreSQL_0.7-3 DBI_1.1.1.9000
[33] odbc_1.3.2.9000 pmdplyr_0.3.4
[35] ExPanDaR_0.5.3 fastDummies_1.6.3
[37] DescTools_0.99.43 openxlsx_4.2.4
[39] devEMF_4.0-2 rvg_0.2.5
[41] rsvg_2.1.2 xml2_1.3.3
[43] validata_0.1.0 ftExtra_0.2.0
[45] huxtable_5.4.0.9000 flextable_0.6.10
[47] sjlabelled_1.1.8 safejoin_0.1.0
[49] diffdf_1.0.4 corrplot_0.90
[51] flipTime_2.9.4 slider_0.2.2.9000
[53] tsibbledata_0.3.0 feasts_0.2.2
[55] fabletools_0.3.1 tsibble_1.1.0
[57] plm_2.4-3 outliers_0.14
[59] lfe_2.8-7 stargazer_5.2.2
[61] arsenal_3.6.3 janitor_2.1.0
[63] qwraps2_0.5.2 kableExtra_1.3.4
[65] psych_2.1.9 xtable_1.8-4
[67] basictabler_1.0.2 descr_1.1.5
[69] gt_0.3.1 gtsummary_1.5.0
[71] officer_0.4.1 tidycensus_1.1
[73] metricsgraphics_0.9.0 Hmisc_4.6-0
[75] Formula_1.2-4 survival_3.2-11
[77] lattice_0.20-45 summarytools_1.0.0
[79] skimr_2.1.3 tidyquant_1.0.3
[81] lubridate_1.8.0 tmap_3.3-2
[83] broom_0.7.9 mapview_2.10.0
[85] rgdal_1.5-27 sp_1.4-5
[87] sf_1.0-3 RColorBrewer_1.1-2
[89] mapdeck_0.3.4 googleway_2.7.4001
[91] glue_1.5.1 anomalize_0.2.2
[93] transformr_0.1.3 gganimate_1.0.7
[95] RgoogleMaps_1.4.5.3 gifski_1.4.3-1
[97] ggmap_3.0.0.903 microbenchmark_1.4-7
[99] reshape2_1.4.4 gtrendsR_1.5.0.9000
[101] installr_0.23.2 rlang_0.4.12
[103] haven_2.4.3 pbapply_1.5-0
[105] pander_0.6.4 dygraphs_1.1.1.6
[107] ff_4.0.4 bit_4.0.4
[109] data.table_1.14.3 anytime_0.3.9
[111] readxl_1.3.1 forcats_0.5.1
[113] dplyr_1.0.7 purrr_0.3.4
[115] readr_2.1.1 tidyr_1.1.4
[117] tibble_3.1.6 tidyverse_1.3.1
[119] stringr_1.4.0 stringi_1.7.6
[121] mnormt_2.0.2 ggplot2_3.3.5
[123] plyr_1.8.6 gdata_2.18.0
[125] compare_0.2-6 PerformanceAnalytics_2.0.4 [127] quantmod_0.4.18 TTR_0.24.2
[129] xts_0.12.1 timeSeries_3062.100
[131] timeDate_3043.102 foreign_0.8-81
[133] qpcR_1.4-1 Matrix_1.3-4
[135] robustbase_0.93-9 rgl_0.107.14
[137] minpack.lm_1.2-1 MASS_7.3-54
[139] zoo_1.8-9 sas7bdat_0.5
[141] iterators_1.0.13 foreach_1.5.1
[143] listviewer_3.0.0 ellipsis_0.3.2
[145] curl_4.3.2 checkpoint_1.0.0
[147] devtools_2.4.2 usethis_2.1.3
[149] pacman_0.5.1

loaded via a namespace (and not attached): [1] terra_1.4-11 tcltk_4.1.1
[3] vctrs_0.3.8 expm_0.999-6
[5] blob_1.2.2 later_1.3.0
[7] rappdirs_0.3.3 forecast_8.15
[9] distributional_0.2.2 jpeg_0.1-9
[11] htmlwidgets_1.5.4 mvtnorm_1.1-3
[13] tseries_0.10-48 miscTools_0.6-26
[15] parallel_4.1.1 DEoptimR_1.0-9
[17] KernSmooth_2.23-20 DT_0.19
[19] satellite_1.0.4 promises_1.2.0.1
[21] pkgload_1.2.3 magick_2.7.3
[23] leaflet_2.0.4.1 RcppParallel_5.1.4
[25] fs_1.5.1 ranger_0.13.1
[27] png_0.1-7 pkgconfig_2.0.3
[29] warp_0.2.0 xfun_0.28
[31] tidyselect_1.1.1 viridisLite_0.4.0
[33] pkgbuild_1.2.0 gdtools_0.2.3
[35] pryr_0.1.5 modelr_0.1.8
[37] matrixStats_0.61.0 tictoc_1.0.1
[39] ggsignif_0.6.3 maptools_1.1-2
[41] httpuv_1.6.3 class_7.3-19
[43] Rttf2pt1_1.3.9 clipr_0.7.1
[45] framecleaner_0.2.0 webshot_0.5.2
[47] tmvnsim_1.0-2 mime_0.12
[49] systemfonts_1.0.3 fracdiff_1.5-1
[51] gridExtra_2.3 Exact_3.0
[53] insight_0.14.5 processx_3.5.2
[55] rbibutils_2.2.4 quadprog_1.5-8
[57] bitops_1.0-7 cli_3.1.0.9000
[59] Rdpack_2.1.2 rstudioapi_0.13
[61] units_0.7-2 nlme_3.1-153
[63] lpSolve_5.6.15 pak_0.1.2.9001
[65] miniUI_0.1.1.1 stars_0.5-3
[67] dbplyr_2.1.1 sessioninfo_1.1.1
[69] lifecycle_1.0.1 stinepack_1.4
[71] Quandl_2.11.0 munsell_0.5.0
[73] cellranger_1.1.0 codetools_0.2-18
[75] lmtest_0.9-38 htmlTable_2.3.0
[77] classInt_0.4-3 imputeTS_3.2
[79] abind_1.4-5 farver_2.1.0
[81] credentials_1.3.2 rapportools_1.0
[83] askpass_1.1 logger_0.2.2
[85] shinythemes_1.2.0 dichromat_2.0-0
[87] cluster_2.1.2 extrafontdb_1.0
[89] dreamerr_1.2.3 shinyBS_0.61
[91] prettyunits_1.1.1 reprex_2.0.1
[93] gitcreds_0.1.1 tables_0.9.6
[95] hrbrthemes_0.8.0 RcppEigen_0.3.3.9.1
[97] pdp_0.7.0 shinyjs_2.0.0
[99] remotes_2.4.1 testthat_3.1.0
[101] htmltools_0.5.2 utf8_1.2.2
[103] plotly_4.10.0 XML_3.99-0.8
[105] e1071_1.7-9 ggpubr_0.4.0
[107] withr_2.4.3 bit64_4.0.5
[109] rhandsontable_0.3.8 rootSolve_1.8.2.3
[111] raster_3.5-2 tigris_1.5
[113] leafsync_0.1.0 memoise_2.0.1
[115] evaluate_0.14 RApiSerialize_0.1.0
[117] rio_0.5.29 tzdb_0.2.0
[119] extrafont_0.17 callr_3.7.0
[121] lmom_2.8 ps_1.6.0
[123] fansi_0.5.0 checkmate_2.0.0
[125] cachem_1.0.6 desc_1.4.0
[127] maxLik_1.5-2 rstatix_0.7.0
[129] shinycssloaders_1.0.0 rprojroot_2.0.2
[131] sandwich_3.0-1 magrittr_2.0.1
[133] proxy_0.4-26 car_3.0-11
[135] broom.helpers_1.4.0 assertthat_0.2.1
[137] rmarkdown_2.11.3 boot_1.3-28
[139] R6_2.5.1 nnet_7.3-16
[141] progress_1.2.2 gtools_3.9.2
[143] repr_1.1.3 urca_1.3-0
[145] splines_4.1.1 snakecase_0.11.0
[147] carData_3.0-4 colorspace_2.0-2
[149] generics_0.1.1 stats4_4.1.1
[151] base64enc_0.1-3 gridtext_0.1.4
[153] pillar_1.6.4 tweenr_1.0.2
[155] uuid_1.0-3 gtable_0.3.0
[157] bdsmatrix_1.3-4 zip_2.2.0
[159] stringfish_0.15.4 knitr_1.36
[161] RcppArmadillo_0.10.7.0.0 latticeExtra_0.6-29
[163] fastmap_1.1.0 crosstalk_1.2.0
[165] leafem_0.1.6 openssl_1.4.5
[167] scales_1.1.1 backports_1.4.0
[169] lwgeom_0.2-8 vroom_1.5.7
[171] gld_2.6.2 hms_1.1.1
[173] shiny_1.7.1 grid_4.1.1
[175] numDeriv_2016.8-1.1 tmaptools_3.1-1
[177] lazyeval_0.2.2 crayon_1.4.2
[179] svglite_2.0.0 rpart_4.1-15
[181] ggtext_0.1.1 compiler_4.1.1

davidgohel commented 2 years ago

This is very connected to https://stackoverflow.com/a/70209519/3315962, I gave an answer less than an hour ago using flextable as asked in the title of the post.

I don't think there is any bug with colformat_double().

colformat_double() is supposed to do something on columns of type double. The output of huxtable shows it is transforming input data as character data which make not possible to use flextable functions like colformat_double() as there is no more numeric/double column in the result of huxtable.

> xx <- lm(formula=mpg~cyl+hp, mtcars) %>% huxtable::huxreg() %>% huxtable::as_flextable()
> str(xx$body$dataset)
'data.frame':   12 obs. of  2 variables:
 $ names : chr  "" "(Intercept)" "" "cyl" ...
 $ model1: chr  "(1)" "36.908 ***" "(2.191)   " "-2.265 ***" ...

huxtable implemented a function named huxtable::as_flextable which may conflict with flextable::as_flextable. Not sure if it matters or not.

I don't maintain huxtable and can not really help, If you want to use huxtable, you should instead open an issue in huxtable repo.

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.