Skip to content

Commit 722eac2

Browse files
authored
Merge pull request #2010 from shannonhaughton/gt_group
Enable cols_align and cols_label for gt_group objects
2 parents 81efd13 + 227ea10 commit 722eac2

18 files changed

+196
-24
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ importFrom(dplyr,vars)
255255
importFrom(htmltools,as.tags)
256256
importFrom(htmltools,css)
257257
importFrom(magrittr,"%>%")
258+
importFrom(rlang,caller_env)
258259
importFrom(tidyselect,all_of)
259260
importFrom(tidyselect,any_of)
260261
importFrom(tidyselect,contains)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
* Fixed an issue where grand summary rows would not be saved properly to Word (@olivroy, #2000).
1414

15+
* Enable `cols_align()` and `cols_label()` functions for gt_group objects (@shannonhaughton, #2005)
16+
1517
# gt 1.0.0
1618

1719
## Minor improvements and bug fixes

R/cols_align.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@
3333
#' allow **gt** to automatically choose the alignment of each column based on
3434
#' the data type (with the `auto` option).
3535
#'
36-
#' @param data *The gt table data object*
36+
#' @param data *The gt table or gt group data object*
3737
#'
3838
#' `obj:<gt_tbl>` // **required**
3939
#'
4040
#' This is the **gt** table object that is commonly created through use of the
4141
#' [gt()] function.
4242
#'
43+
#' OR
44+
#'
45+
#' `obj:<gt_group>` // **required**
46+
#'
47+
#' This is the **gt** group object that is commonly created through use of the
48+
#' [gt_group()] function.
49+
#'
4350
#' @param align *Alignment type*
4451
#'
4552
#' `singl-kw:[auto|left|center|right]` // *default:* `"auto"`
@@ -111,10 +118,16 @@ cols_align <- function(
111118
) {
112119

113120
# Perform input object validation
114-
stop_if_not_gt_tbl(data = data)
121+
stop_if_not_gt_tbl_or_group(data = data)
122+
123+
# Handle gt_group
124+
if(inherits(data, "gt_group")){
125+
arg_list <- as.list(match.call())
126+
return(apply_to_grp(data, arg_list))
127+
}
115128

116129
# Get the `align` value, this stops the function if there is no match
117-
align <-
130+
align <-
118131
rlang::arg_match0(
119132
align,
120133
values = c("auto", "left", "center", "right")

R/cols_align_decimal.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' number of columns (the function will skip over columns that don't require
3434
#' this type of alignment).
3535
#'
36-
#' @inheritParams cols_align
36+
#' @inheritParams cols_hide
3737
#'
3838
#' @param columns *Columns to target*
3939
#'

R/cols_hide.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
#' reference during formatting of other columns) but the final display of those
3535
#' columns is not necessary.
3636
#'
37-
#' @inheritParams cols_align
37+
#' @param data *The gt table data object*
38+
#'
39+
#' `obj:<gt_tbl>` // **required**
40+
#'
41+
#' This is the **gt** table object that is commonly created through use of the
42+
#' [gt()] function.
3843
#'
3944
#' @param columns *Columns to target*
4045
#'
@@ -162,7 +167,7 @@ cols_hide <- function(
162167
#' be important in cases where the user obtains a `gt_tbl` object with hidden
163168
#' columns and there is motivation to reveal one or more of those.
164169
#'
165-
#' @inheritParams cols_align
170+
#' @inheritParams cols_hide
166171
#'
167172
#' @param columns *Columns to target*
168173
#'

R/cols_label.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#' we even have the option to use [md()] or [html()] for rendering column labels
3636
#' from Markdown or using HTML.
3737
#'
38-
#' @inheritParams cols_width
38+
#' @inheritParams cols_align
3939
#'
4040
#' @param ... *Column label assignments*
4141
#'
@@ -336,7 +336,13 @@ cols_label <- function(
336336
) {
337337

338338
# Perform input object validation
339-
stop_if_not_gt_tbl(data = .data)
339+
stop_if_not_gt_tbl_or_group(data = .data)
340+
341+
# Handle gt_group
342+
if(inherits(.data, "gt_group")){
343+
arg_list <- as.list(match.call())
344+
return(apply_to_grp(.data, arg_list))
345+
}
340346

341347
if (!is.null(.process_units) && .process_units) {
342348

R/cols_merge.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#' columns (i.e., second and subsequent columns given in `columns`). The
3838
#' formatting of values in different columns will be preserved upon merging.
3939
#'
40-
#' @inheritParams cols_align
40+
#' @inheritParams cols_hide
4141
#'
4242
#' @param columns *Columns to target*
4343
#'
@@ -291,7 +291,7 @@ cols_merge <- function(
291291
#' uncertainties, and any columns specified in `col_uncert` are hidden from
292292
#' appearing the output table.
293293
#'
294-
#' @inheritParams cols_align
294+
#' @inheritParams cols_hide
295295
#'
296296
#' @param col_val *Column to target for base values*
297297
#'
@@ -478,7 +478,7 @@ cols_merge_uncert <- function(
478478
#' containing both values separated by an em dash. The column specified in
479479
#' `col_end` is dropped from the output table.
480480
#'
481-
#' @inheritParams cols_align
481+
#' @inheritParams cols_hide
482482
#'
483483
#' @param col_begin *Column to target for beginning of range*
484484
#'
@@ -691,7 +691,7 @@ cols_merge_range <- function(
691691
#' percentages (e.g., `12 (23.2%)`). The column specified in `col_pct` is
692692
#' dropped from the output table.
693693
#'
694-
#' @inheritParams cols_align
694+
#' @inheritParams cols_hide
695695
#'
696696
#' @param col_n *Column to target for counts*
697697
#'

R/cols_move.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#' `columns` to be moved is preserved, as is the ordering of all other columns
3737
#' in the table.
3838
#'
39-
#' @inheritParams cols_align
39+
#' @inheritParams cols_hide
4040
#'
4141
#' @param columns *Columns to target*
4242
#'
@@ -185,7 +185,7 @@ cols_move <- function(
185185
#' start is preserved (same with the ordering of all other columns in the
186186
#' table).
187187
#'
188-
#' @inheritParams cols_align
188+
#' @inheritParams cols_hide
189189
#'
190190
#' @param columns *Columns to target*
191191
#'
@@ -311,7 +311,7 @@ cols_move_to_start <- function(
311311
#' error prone. The ordering of the `columns` that are moved to the end is
312312
#' preserved (same with the ordering of all other columns in the table).
313313
#'
314-
#' @inheritParams cols_align
314+
#' @inheritParams cols_hide
315315
#'
316316
#' @param columns *Columns to target*
317317
#'

R/modify_rows.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#' top of the table and the remaining row groups will follow in their original
3636
#' ordering.
3737
#'
38-
#' @inheritParams cols_align
38+
#' @inheritParams cols_hide
3939
#'
4040
#' @param groups *Specification of row group IDs*
4141
#'

R/nanoplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#' helper, layers of the nanoplots can be selectively removed and the aesthetics
7777
#' of the remaining plot components can be modified.
7878
#'
79-
#' @inheritParams cols_align
79+
#' @inheritParams cols_hide
8080
#'
8181
#' @param columns *Columns from which to get data for the dependent variable*
8282
#'

0 commit comments

Comments
 (0)