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

1.4.2 #665

Closed
wants to merge 5 commits into from
Closed

1.4.2 #665

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<doi:10.18637/jss.v103.i01>.
Version: 1.4.1.9010
Version: 1.4.2
Authors@R: c(person("Vincent", "Arel-Bundock",
email = "[email protected]",
role = c("aut", "cre"),
Expand Down Expand Up @@ -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),
Expand All @@ -63,7 +63,6 @@ Suggests:
betareg,
bookdown,
brms,
rstanarm,
broom,
broom.mixed,
car,
Expand All @@ -74,19 +73,18 @@ Suggests:
DT,
estimatr,
fixest,
tictoc,
flextable,
future,
future.apply,
gamlss,
ggdist,
ggplot2,
gt (>= 0.8.0),
gtExtras,
haven,
huxtable,
IRdisplay,
ivreg,
kableExtra (>= 1.3.4),
knitr,
lavaan,
lfe,
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# modelsummary 1.4.1 (development)
# modelsummary 1.4.2

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:

Expand Down
54 changes: 36 additions & 18 deletions R/datasummary_skim.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -174,20 +174,24 @@ 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
}
}
}

# 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.')
}

}
Expand Down Expand Up @@ -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(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]
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"))) {
Expand Down
10 changes: 10 additions & 0 deletions R/factory_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -79,6 +88,7 @@ typstable <- function(
inset: %s,
columns: %s,
align: %s,
stroke: none,
%s
)",
inset, columns, align, tab)
Expand Down
4 changes: 4 additions & 0 deletions inst/tinytest/test-datasummary_skim.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down