From 14524fa3c7b7a5220bc9f6575473c5309077d181 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Wed, 17 Jul 2024 18:25:25 -0400 Subject: [PATCH 1/4] Add light-switch option for pkgdown site --- pkgdown/_pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index c8db36101a..e821fa3c03 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -7,6 +7,7 @@ home: template: bootstrap: 5 + light-switch: true assets: pkgdown/assets authors: From b0cef90eda909e1263e54e4641dede3a43e99f8f Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 17 Jul 2024 18:26:37 -0400 Subject: [PATCH 2/4] Fix grid output with unique groups --- NEWS.md | 4 ++++ R/utils_render_grid.R | 11 ++++++++--- tests/testthat/test-as_gtable.R | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 804255faf5..1c27d48666 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,6 +27,10 @@ * Fixed a bug in using `pct()` column widths with `as_gtable()` (@teunbrand, #1771) +* Fixed a bug where `gt(row_group_as_column = TRUE)` would create the wrong layout with `as_gtable()` when all groups are unique (@olivroy, #1803). + +* grid output has been improved. Namely, showing currency symbols now works (@olivroy, #1788). + * `data_color()` no longer errors when a tidyselect selection is empty (like `fmt_*()` functions) (@olivroy, #1665). # gt 0.11.0 diff --git a/R/utils_render_grid.R b/R/utils_render_grid.R index 3ad530d8fb..fd4f5aa3e5 100644 --- a/R/utils_render_grid.R +++ b/R/utils_render_grid.R @@ -542,7 +542,7 @@ body_cells_g <- function(data) { ) if (has_two_col_stub) { - # Set stub row group + # Set stub row group(s) group_cell <- which(cell_rows %in% groups$row_start & cell_cols == 1) group <- match(cell_rows[group_cell], groups$row_start) extra_rows <- (groups$row_end - groups$row_start + 1)[group] @@ -562,8 +562,13 @@ body_cells_g <- function(data) { # Delete empty cells delete <- which(!(cell_rows %in% groups$row_start) & cell_cols == 1) - layout <- vctrs::vec_slice(layout, -delete) - cell_rows <- vctrs::vec_slice(cell_rows, -delete) + + if (rlang::has_length(delete)) { + # don't attempt delete doesn't have length + # will likely occur in the case of all groups of length 1 #1803 + layout <- vctrs::vec_slice(layout, -delete) + cell_rows <- vctrs::vec_slice(cell_rows, -delete) + } } # Split by row diff --git a/tests/testthat/test-as_gtable.R b/tests/testthat/test-as_gtable.R index 5420c3f4d6..bb0f146747 100644 --- a/tests/testthat/test-as_gtable.R +++ b/tests/testthat/test-as_gtable.R @@ -177,3 +177,21 @@ test_that("gtable outputs works well for currencies", { as_gtable(tbl) ) }) + +test_that("gtable output works when row groups are unique (#1802).", { + # using groupname_col = "row" to ensure uniqueness + tbl <- exibble %>% + gt(groupname_col = "row") + expect_no_error(test <- as_gtable(tbl)) + expect_equal( + test$layout$name[8], + "column_label_8" + ) + tbl <- exibble %>% + gt(groupname_col = "row", row_group_as_column = TRUE) + expect_no_error(test <- as_gtable(tbl)) + expect_equal( + test$layout$name[8], + "column_label_8" + ) +}) From 4e1ca1fe960294ea2871686a3111b389a7ef97c8 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Wed, 17 Jul 2024 22:04:39 -0400 Subject: [PATCH 3/4] Fix pkgdown description of datasets --- pkgdown/_pkgdown.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index e821fa3c03..0b99d01b20 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -362,10 +362,10 @@ reference: - title: Built in datasets desc: > - The **gt** package is equipped with twelve datasets that come in all - shapes and sizes. Use them to experiment with the package! Many examples - in the internal help documents use these datasets to quickly demonstrate - the awesome features of **gt**. + The **gt** package is equipped with 18 datasets that come in all shapes + and sizes. Use them to experiment with the package! Many examples in the + documentation use these datasets to demonstrate the awesome features of + **gt**. contents: - countrypops - sza From cf3c1708bd55334aec5d034c8de9eb31c09435a4 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Wed, 17 Jul 2024 22:05:14 -0400 Subject: [PATCH 4/4] Tweak pkgdown CSS for dark mode considerations --- pkgdown/extra.css | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgdown/extra.css b/pkgdown/extra.css index 83d77b33d0..cf22d5819a 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -25,7 +25,6 @@ h4, .h4 { } dt { - color: rgb(38, 38, 38); text-decoration: underline; text-decoration-style: solid; text-underline-offset: 4px;