Skip to content

Commit

Permalink
Fix apply_table_theme() (#856)
Browse files Browse the repository at this point in the history
* Fix `apply_table_theme()`
Fixes #855

* use theme_tt

* docs

* test

* updatew wordlist
  • Loading branch information
strengejacke authored Mar 12, 2024
1 parent 0549cf7 commit 9d4bfaf
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.19.8.8
Version: 0.19.8.9
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -193,7 +193,7 @@ Suggests:
survey,
survival,
testthat,
tinytable,
tinytable (>= 0.1.0),
truncreg,
tweedie,
TMB,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

* `format_ci()` now works for factors and character vectors again.

* Fixed issues with latest release of _tinytable_.

# insight 0.19.8

## General
Expand Down
16 changes: 7 additions & 9 deletions R/apply_table_theme.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @param out A `tinytable` object.
#' @param x The underlying data frame, used to create `out`.
#' @param theme The theme to apply to the table. One of `"default"`, `"grid"`,
#' `"striped"`, `"bootstrap"`, or `"darklines"`.
#' `"striped"`, `"bootstrap"`, `"void"`, `"tabular"`, or `"darklines"`.
#' @param sub_header_positions A vector of row positions to apply a border to.
#' Currently particular for internal use of other _easystats_ packages.
#' @rdname export_table
Expand All @@ -13,17 +13,15 @@ apply_table_theme <- function(out, x, theme = "default", sub_header_positions =
}

# packages available?
check_if_installed("tinytable")
check_if_installed("tinytable", minimum_version = "0.1.0")

switch(theme,
grid = {
out <- tinytable::tt(out, theme = "grid")
},
striped = {
out <- tinytable::tt(out, theme = "striped")
},
grid = ,
striped = ,
tabular = ,
void = ,
bootstrap = {
out <- tinytable::tt(out, theme = "bootstrap")
out <- tinytable::theme_tt(out, theme = theme)
},
darklines = {
# borders for sub headings
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ systemfit
terciles
th
tidymodels
tinytable
tranformations
tseries
tweedie
Expand Down
2 changes: 1 addition & 1 deletion man/export_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-apply_table_theme.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
skip_if_not_installed("tinytable", minimum_version = "0.1.0")

test_that("apply_table_theme", {
x <- mtcars[1:4, 1:3]
out <- tinytable::tt(x)
out@output <- "html"
expect_s4_class(apply_table_theme(out, x, theme = "bootstrap"), "tinytable")
expect_s4_class(apply_table_theme(out, x, theme = "darklines"), "tinytable")
expect_s4_class(apply_table_theme(out, x, theme = NULL), "tinytable")
})

0 comments on commit 9d4bfaf

Please sign in to comment.