Skip to content

Commit 7daea56

Browse files
committed
merge main
2 parents 27e9913 + db55019 commit 7daea56

33 files changed

+141
-135
lines changed

CITATION.cff

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ message: 'If you wish to cite the "gt" package use:'
33
type: software
44
license: MIT
55
title: 'gt: Easily Create Presentation-Ready Display Tables'
6-
version: 0.10.1
6+
version: 0.11.0
77
abstract: Build display tables from tabular data with an easy-to-use set of functions.
88
With its progressive approach, we can construct display tables with a cohesive set
99
of table parts. Table values can be formatted using any of the included formatting
@@ -34,7 +34,13 @@ authors:
3434
given-names: JooYoung
3535
3636
orcid: https://orcid.org/0000-0002-4064-6012
37-
repository: https://CRAN.R-project.org/package=gt
37+
- family-names: Ken
38+
given-names: Brevoort
39+
40+
orcid: https://orcid.org/0000-0002-4001-8358
41+
- family-names: Olivier
42+
given-names: Roy
43+
repository: https://doi.org/10.32614/CRAN.package.gt
3844
repository-code: https://github.com/rstudio/gt
3945
url: https://gt.rstudio.com
4046
contact:

R/cols_align_decimal.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ cols_align_decimal <- function(
173173
# helper -----------------------------------
174174
align_to_char <- function(x, align_at = ".") {
175175

176-
na_x_vals <- grepl("^NA$", x)
176+
na_x_vals <- x == "NA"
177177
no_a_char <- !grepl(align_at, x, fixed = TRUE) & !grepl("[0-9]", x)
178178
has_t_dec <- grepl("[0-9]\\.$", x)
179179

@@ -225,7 +225,7 @@ align_to_char <- function(x, align_at = ".") {
225225

226226
x_piece_rhs[i] <-
227227
gsub(
228-
paste0(paste(rep("\U02007", n_char_extracted), collapse = ""), "$"),
228+
paste0(strrep("\U02007", n_char_extracted), "$"),
229229
"",
230230
x_piece_rhs[i]
231231
)
@@ -238,15 +238,15 @@ align_to_char <- function(x, align_at = ".") {
238238

239239
if (grepl(align_at, paste(x[!x_no_align], collapse = "|"), fixed = TRUE)) {
240240

241-
x_align[!nchar(x_rhs) > 0 & !grepl(align_at, x[!x_no_align], fixed = TRUE)] <-
242-
sub(align_at, " ", x_align[!nchar(x_rhs) > 0], fixed = TRUE)
241+
x_align[nchar(x_rhs) == 0 & !grepl(align_at, x[!x_no_align], fixed = TRUE)] <-
242+
sub(align_at, " ", x_align[nchar(x_rhs) == 0], fixed = TRUE)
243243

244244
x_align[x_align_parens] <- paste0(x_align[x_align_parens], "\U000A0")
245245

246246
} else {
247247

248-
x_align[!nchar(x_rhs) > 0 & !grepl(align_at, x[!x_no_align], fixed = TRUE)] <-
249-
sub(align_at, "", x_align[!nchar(x_rhs) > 0], fixed = TRUE)
248+
x_align[nchar(x_rhs) == 0 & !grepl(align_at, x[!x_no_align], fixed = TRUE)] <-
249+
sub(align_at, "", x_align[nchar(x_rhs) == 0], fixed = TRUE)
250250

251251
x_align[!x_align_parens] <- paste0(x_align[!x_align_parens], "\U000A0")
252252
}

R/cols_merge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ cols_merge <- function(
245245

246246
hide_columns_from_supplied <- base::intersect(hide_columns, columns)
247247

248-
if (length(base::setdiff(hide_columns, columns) > 0)) {
248+
if (length(base::setdiff(hide_columns, columns)) > 0) {
249249
cli::cli_warn(c(
250250
"Only a subset of columns supplied in `columns` will be hidden.",
251251
"*" = "Use an additional `cols_hide()` expression to hide any

R/compile_scss.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ compile_scss <- function(data, id = NULL) {
3636
gt_options_tbl <-
3737
within(
3838
gt_options_tbl, {
39-
value[color_rows] = value[color_rows] <-
39+
value[color_rows] <- value[color_rows] <-
4040
lapply(value[color_rows], html_color)
4141
}
4242
)

R/export.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ grid_align_gtable <- function(gtable, data) {
927927

928928
left <- grid::unit(0.5, "null")
929929

930-
} else if (grepl("\\%$", left)) {
930+
} else if (endsWith(left, "%")) {
931931

932932
left <- as.numeric(sub("\\%$", "", left)) / 100
933933
left <- grid::unit(left * 0.5, "null")
@@ -941,7 +941,7 @@ grid_align_gtable <- function(gtable, data) {
941941

942942
right <- grid::unit(0.5, "null")
943943

944-
} else if (grepl("\\%$", right)) {
944+
} else if (endsWith(right, "%")) {
945945

946946
right <- as.numeric(sub("\\%$", "", right)) / 100
947947
right <- grid::unit(right * 0.5, "null")
@@ -1005,7 +1005,7 @@ grid_layout_widths <- function(layout, data) {
10051005

10061006
total_width <- dt_options_get_value(data, "table_width")
10071007

1008-
if (grepl("px$", total_width)) {
1008+
if (endsWith(total_width, "px")) {
10091009

10101010
total_width <- parse_px_to_pt(total_width)
10111011
extra_width <- total_width - sum(widths)
@@ -1023,7 +1023,7 @@ grid_layout_widths <- function(layout, data) {
10231023
return(widths)
10241024
}
10251025

1026-
if (grepl("\\%$", total_width)) {
1026+
if (endsWith(total_width, "%")) {
10271027

10281028
# Set the total width in npc units
10291029
total_width <- as.numeric(sub("\\%$", "", total_width)) / 100

R/fmt.R

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ format_num_to_str <- function(
635635
is_inf <- grepl("Inf", x_str, fixed = TRUE)
636636
x_str_numeric <- x_str[!is_inf]
637637
has_decimal <- grepl(".", x_str_numeric, fixed = TRUE)
638-
is_negative <- grepl("^-", x_str_numeric)
638+
is_negative <- startsWith(x_str_numeric, "-")
639639

640640
integer_parts <- sub("\\..*", "", x_str_numeric)
641641

@@ -757,23 +757,22 @@ to_latex_math_mode <- function(x, context) {
757757

758758
return(x)
759759

760-
} else {
761-
762-
# Ensure that `$` signs only surround the correct number parts
763-
# - certain LaTeX marks operate only in text mode and we need to
764-
# conditionally surround only the number portion in these cases
765-
# - right now, the only marks that need to be situated outside of
766-
# the math context are the per mille and per myriad (10,000)
767-
# marks (provided by the `fmt_per()` function)
768-
if (all(grepl("\\\\textper(ten)?thousand$", x))) {
769-
out <- paste0("$", x)
770-
out <- gsub("(\\s*?\\\\textper(ten)?thousand)", "$\\1", out)
771-
} else {
772-
out <- paste_between(x, x_2 = c("$", "$"))
773-
}
760+
}
774761

775-
return(out)
762+
# Ensure that `$` signs only surround the correct number parts
763+
# - certain LaTeX marks operate only in text mode and we need to
764+
# conditionally surround only the number portion in these cases
765+
# - right now, the only marks that need to be situated outside of
766+
# the math context are the per mille and per myriad (10,000)
767+
# marks (provided by the `fmt_per()` function)
768+
if (all(grepl("\\\\textper(ten)?thousand$", x))) {
769+
out <- paste0("$", x)
770+
out <- gsub("(\\s*?\\\\textper(ten)?thousand)", "$\\1", out)
771+
} else {
772+
out <- paste_between(x, x_2 = c("$", "$"))
776773
}
774+
775+
return(out)
777776
}
778777

779778
#' Obtain the contextually correct minus mark

R/format_data.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ fmt_fraction <- function(
23692369

23702370
gcd <- function(x,y) {
23712371
r <- x %% y
2372-
return(ifelse(r, gcd(y, r), y))
2372+
ifelse(r, gcd(y, r), y)
23732373
}
23742374

23752375
make_frac <- function(x, denom, simplify = TRUE) {
@@ -7114,7 +7114,7 @@ fmt_tf <- function(
71147114
# If using SVG graphics for either of `true_val` or `false_val` then
71157115
# we'd prefer to have center alignment of the icons
71167116
if (
7117-
grepl("^<svg ", true_val) || grepl("^<svg ", false_val)
7117+
startsWith(true_val, "<svg ") || startsWith(false_val, "<svg ")
71187118
) {
71197119
alignment <- "center"
71207120
}
@@ -8263,7 +8263,7 @@ fmt_url <- function(
82638263
target <- target %||% "_blank"
82648264
target_values <- NULL
82658265

8266-
if (grepl("^_", target)) {
8266+
if (startsWith(target, "_")) {
82678267
target_values <- c("_blank", "_self", "_parent", "_top")
82688268
}
82698269

@@ -8951,7 +8951,7 @@ fmt_email <- function(
89518951
target <- target %||% "_blank"
89528952
target_values <- NULL
89538953

8954-
if (grepl("^_", target)) {
8954+
if (startsWith(target, "_")) {
89558955
target_values <- c("_blank", "_self", "_parent", "_top")
89568956
}
89578957

@@ -9018,9 +9018,8 @@ fmt_email <- function(
90189018
label_separated <- unlist(strsplit(label_str, " "))
90199019

90209020
} else if (
9021-
grepl("^<", label_str) &&
9022-
grepl(">$", label_str) &&
9023-
!grepl("^<svg", label_str)
9021+
grepl("^<.*>$", label_str) &&
9022+
!startsWith(label_str, "<svg")
90249023
) {
90259024

90269025
label_separated <- unlist(strsplit(label_str, ">\\s*<"))

R/helpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ cells_title <- function(groups = c("title", "subtitle")) {
11141114
!is.character(groups) ||
11151115
length(groups) < 1 ||
11161116
!all(groups %in% c("title", "subtitle")) ||
1117-
any(duplicated(groups))
1117+
anyDuplicated(groups) > 0L
11181118
) {
11191119
cli::cli_abort(
11201120
"`groups` must be either {.val title}, {.val subtitle}, or both."

R/opts.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,9 @@ opt_all_caps <- function(
11741174

11751175
values_vec <-
11761176
dplyr::case_when(
1177-
grepl("\\.font\\.size$", options_vec) ~ "80%",
1178-
grepl("\\.font\\.weight$", options_vec) ~ "bolder",
1179-
grepl("\\.text_transform$", options_vec) ~ "uppercase"
1177+
endsWith(options_vec, ".font.size") ~ "80%",
1178+
endsWith(options_vec, ".font.weight") ~ "bolder",
1179+
endsWith(options_vec, ".text_transform") ~ "uppercase"
11801180
)
11811181

11821182
option_value_list <- create_option_value_list(options_vec, values_vec)

R/render_as_i_html.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ render_as_ihtml <- function(data, id) {
190190
column_labels_border_bottom_color <- opt_val(data = data, option = "column_labels_border_bottom_color")
191191

192192
# Don't allow NA
193-
column_labels_background_color = opt_val(data = data, option = "column_labels_background_color")
193+
column_labels_background_color <- opt_val(data = data, option = "column_labels_background_color")
194194
if (is.na(column_labels_background_color)) {
195195
# apply all column labels formatting to both heading + groupCol styling (nothing specific for spanners styling in gt?)
196196
column_labels_background_color <- "transparent"
197197
}
198198

199199
column_labels_font_weight <- opt_val(data = data, option = "column_labels_font_weight")
200+
# Apply stub font weight to
201+
stub_font_weight <- opt_val(data = data, option = "stub_font_weight")
200202
# Apply font weight to groupname_col title
201203
row_group_font_weight <- opt_val(data = data, "row_group_font_weight")
202204
row_group_background_color <- opt_val(data = data, "row_group_background_color")
@@ -215,7 +217,6 @@ render_as_ihtml <- function(data, id) {
215217
all_borders <- horizontal_borders != "none" && veritcal_borders != "none"
216218

217219
# for row names + summary label
218-
stub_font_weight <- opt_val(data = data, "stub_font_weight")
219220
stub_border_color <- opt_val(data, "stub_border_color")
220221
stub_border_style <- opt_val(data, "stub_border_style")
221222
# Apply stub font weight to

0 commit comments

Comments
 (0)