From 949ee798512648f0112d2fe1b7e1885f60a882f6 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 15 Aug 2023 21:09:40 -0400 Subject: [PATCH 1/5] 1.4.2 --- DESCRIPTION | 5 ++--- NEWS.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe77f04cb..b817fc952 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Create beautiful and customizable tables to summarize several RTF, JPG, or PNG. Tables can easily be embedded in 'Rmarkdown' or 'knitr' dynamic documents. Details can be found in Arel-Bundock (2022) . -Version: 1.4.1.9010 +Version: 1.4.2 Authors@R: c(person("Vincent", "Arel-Bundock", email = "vincent.arel-bundock@umontreal.ca", role = c("aut", "cre"), @@ -52,7 +52,7 @@ Imports: data.table, generics, glue, - kableExtra, + kableExtra (>= 1.3.4), insight (>= 0.19.1), parameters (>= 0.21.0), performance (>= 0.10.2), @@ -86,7 +86,6 @@ Suggests: huxtable, IRdisplay, ivreg, - kableExtra (>= 1.3.4), knitr, lavaan, lfe, diff --git a/NEWS.md b/NEWS.md index eaf8770aa..d5d5caf09 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# modelsummary 1.4.1 (development) +# modelsummary 1.4.2 New: From c66eb80044e9b84d66601b1c2d1943d9d3368e5a Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 15 Aug 2023 10:27:59 -0400 Subject: [PATCH 2/5] gt supports histograms --- DESCRIPTION | 1 + NEWS.md | 1 + R/datasummary_skim.R | 54 ++++++++++++++++++--------- inst/tinytest/test-datasummary_skim.R | 4 ++ 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b817fc952..056d72d75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -82,6 +82,7 @@ Suggests: ggdist, ggplot2, gt (>= 0.8.0), + gtExtras, haven, huxtable, IRdisplay, diff --git a/NEWS.md b/NEWS.md index d5d5caf09..df9565b87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ New: * Minimal support for `Typst` output, with auto-detection in Quarto documents. * `strip` argument in `dvnames`. * `s.value` statistic is now available whenever `p.value` is available. See Greenland (2019). +* `datasummary_skim()` now includes histograms in `gt` tables. Bugs: diff --git a/R/datasummary_skim.R b/R/datasummary_skim.R index 00a0bf47a..2f7f8e481 100644 --- a/R/datasummary_skim.R +++ b/R/datasummary_skim.R @@ -161,7 +161,7 @@ datasummary_skim_numeric <- function( if (histogram) { # histogram is a kableExtra-specific option - if (!settings_equal("output_factory", "kableExtra")) { + if (!settings_equal("output_factory", c("kableExtra", "gt"))) { histogram <- FALSE } @@ -174,12 +174,16 @@ datasummary_skim_numeric <- function( # interactive or Rmarkdown/knitr } else { if (isTRUE(check_dependency("knitr"))) { - if (!settings_equal("output_format", c("default", "jupyter", "html", "kableExtra")) && + if (!settings_equal("output_format", c("default", "jupyter", "html", "kableExtra", "gt")) && !knitr::is_latex_output()) { histogram <- FALSE } + # gt cannot print histograms in latex + if (knitr::is_latex_output() && settings_equal("output_format", "gt")) { + histogram <- FALSE + } } else { - if (!settings_equal("output_format", c("default", "jupyter", "html", "kableExtra"))) { + if (!settings_equal("output_format", c("default", "jupyter", "html", "kableExtra", "gt"))) { histogram <- FALSE } } @@ -187,7 +191,7 @@ datasummary_skim_numeric <- function( # if flag was flipped if (!histogram) { - insight::format_warning('The histogram argument is only supported for (a) output types "default", "html", or "kableExtra"; (b) writing to file paths with extensions ".html", ".jpg", or ".png"; and (c) Rmarkdown or knitr documents compiled to PDF or HTML. Use `histogram=FALSE` to silence this warning.') + insight::format_warning('The histogram argument is only supported for (a) output types "default", "html", "kableExtra", or "gt"; (b) writing to file paths with extensions ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents compiled to PDF (via kableExtra) or HTML (via kableExtra or gt). Use `histogram=FALSE` to silence this warning.') } } @@ -254,25 +258,39 @@ datasummary_skim_numeric <- function( output_fmt <- output } - # draw table cache <- settings_cache(c("output_format", "output_file", "output_factory")) - out <- datasummary(formula = f, - data = dat_lab, - output = "kableExtra", - # output = output_fmt, - title = title, - align = align, - notes = notes, - escape = escape, - internal_call = TRUE) - settings_restore(cache) - out <- kableExtra::column_spec(out, + out <- datasummary( + formula = f, + data = dat_lab, + output = output_fmt, + title = title, + align = align, + notes = notes, + escape = escape, + internal_call = TRUE) + + if (identical(output_fmt, "gt")) { + insight::check_if_installed("gtExtras") + tmp <- data.table::data.table(a = histogram_list) + out[["_data"]][, ncol(out[["_data"]])] <- tmp[, 1, drop = FALSE] + out <- gtExtras::gt_plt_dist(out, + column = ncol(out[["_data"]]), + type = "histogram", + fill_color = "black", + line_color = "black", + same_limit = FALSE) + + } else { + out <- kableExtra::column_spec(out, column = 9, image = kableExtra::spec_hist(histogram_list, - col = "black", - same_lim = FALSE)) + col = "black", + same_lim = FALSE)) + } + + settings_restore(cache) # don't use output=filepath.html when post-processing if (!is.null(settings_get("output_file"))) { diff --git a/inst/tinytest/test-datasummary_skim.R b/inst/tinytest/test-datasummary_skim.R index faa494f0e..d4d2c6347 100644 --- a/inst/tinytest/test-datasummary_skim.R +++ b/inst/tinytest/test-datasummary_skim.R @@ -107,6 +107,10 @@ tab <- datasummary_skim(penguins) expect_inherits(tab, "kableExtra") +# Issue #627: histograms in gt +expect_inherits(datasummary_skim(mtcars, output = "gt"), "gt_tbl") + + # # RDatasets tests: must be commented out # any_categorical <- function(x) { # # datasummary_skim ignores characters with more than 10 levels From b33871ee00af4210408ccbb5a6196c29cc9498dc Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 15 Aug 2023 10:35:10 -0400 Subject: [PATCH 3/5] bugifx --- R/datasummary_skim.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datasummary_skim.R b/R/datasummary_skim.R index 2f7f8e481..89e703a3d 100644 --- a/R/datasummary_skim.R +++ b/R/datasummary_skim.R @@ -271,7 +271,7 @@ datasummary_skim_numeric <- function( escape = escape, internal_call = TRUE) - if (identical(output_fmt, "gt")) { + if (identical(cache$output_factory, "gt")) { insight::check_if_installed("gtExtras") tmp <- data.table::data.table(a = histogram_list) out[["_data"]][, ncol(out[["_data"]])] <- tmp[, 1, drop = FALSE] From b08ac547dac99f18fc8313760a5c924d2562d2de Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 15 Aug 2023 11:18:58 -0400 Subject: [PATCH 4/5] Issue #646: typst no stroke + escape --- R/factory_typst.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/factory_typst.R b/R/factory_typst.R index a1235622f..c6c081372 100644 --- a/R/factory_typst.R +++ b/R/factory_typst.R @@ -66,6 +66,15 @@ typstable <- function( } else { cn <- NULL } + cn <- gsub("\\*", "\\\\*", cn) + cn <- gsub("\\#", "\\\\#", cn) + + # escape asterisks, which have a special delimiter meaning in Typst + for (i in seq_along(x)) { + x[[i]] <- gsub("\\*", "\\\\*", x[[i]]) + x[[i]] <- gsub("\\#", "\\\\#", x[[i]]) + } + # cells tab <- data.frame(apply(x, 1:2, function(z) sprintf("[%s]", z))) @@ -79,6 +88,7 @@ typstable <- function( inset: %s, columns: %s, align: %s, +stroke: none, %s )", inset, columns, align, tab) From 617fc5d9451b6b8b8def35c982d31a1d98f9d3f9 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 15 Aug 2023 12:09:17 -0400 Subject: [PATCH 5/5] sort suggests --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 056d72d75..f100506cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,6 @@ Suggests: betareg, bookdown, brms, - rstanarm, broom, broom.mixed, car, @@ -74,7 +73,6 @@ Suggests: DT, estimatr, fixest, - tictoc, flextable, future, future.apply, @@ -106,17 +104,19 @@ Suggests: pscl, remotes, rmarkdown, + rstanarm, rsvg, sandwich, spelling, survey, survival, tibble, + tictoc, tidyselect, - tinytex, tidyverse, tinysnapshot, tinytest, + tinytex, wesanderson License: GPL-3 Encoding: UTF-8