Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

* Enable `cols_align()` and `cols_label()` functions for gt_group objects (@shannonhaughton, #2005)

* Enable remaining `cols_*` functions for gt_group objects (@shannonhaughton, #2012)

* `tab_footnote()` + `md()` + docx is now processed correctly (@olivroy, #1892).

# gt 1.0.0
Expand Down
18 changes: 12 additions & 6 deletions R/cols_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#' empty (i.e., all `NA`) columns need to be added, you can use any of the `NA`
#' types (e.g., `NA`, `NA_character_`, `NA_real_`, etc.) for such columns.
#'
#' @inheritParams fmt_number
#' @inheritParams cols_align
#'
#' @param ... *Cell data assignments*
#'
Expand Down Expand Up @@ -226,7 +226,13 @@ cols_add <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = .data)
stop_if_not_gt_tbl_or_group(data = .data)

# Handle gt_group
if(inherits(.data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(.data, arg_list))
}

# Get the table's boxhead
boxh_df <- dt_boxhead_get(data = .data)
Expand Down Expand Up @@ -404,11 +410,11 @@ cols_add <- function(
cli::cli_abort("The expression used for `.after` resolved multiple columns.")
}
}

if (length(resolved_column_after) == 1 && resolved_column_after == colnames(data_tbl)[NCOL(data_tbl)]) {
# if requesting the last column to add after, use NULL instead.
resolved_column_after <- NULL
}
}

# Stop function if expressions are given to both `.before` and `.after`
if (!is.null(resolved_column_before) && !is.null(resolved_column_after)) {
Expand Down Expand Up @@ -441,7 +447,7 @@ cols_add <- function(
} else if (!is.null(resolved_column_before) && is.null(resolved_column_after)) {

before_colnum <- which(colnames(data_tbl) == resolved_column_before)

if (before_colnum <= 1) {
# put new column first
updated_data_tbl <-
Expand Down Expand Up @@ -480,7 +486,7 @@ cols_add <- function(
)

after_colnum <- which(boxh_df[["var"]] == resolved_column_after)

updated_boxh_df <-
vctrs::vec_rbind(
boxh_df[1:after_colnum, ],
Expand Down
11 changes: 9 additions & 2 deletions R/cols_align_decimal.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' number of columns (the function will skip over columns that don't require
#' this type of alignment).
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -113,7 +113,13 @@ cols_align_decimal <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# Resolve the `locale` value here with the global locale value
locale <- resolve_locale(data = data, locale = locale)
Expand Down Expand Up @@ -255,3 +261,4 @@ align_to_char <- function(x, align_at = ".") {

x_str
}

25 changes: 16 additions & 9 deletions R/cols_hide.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
#' reference during formatting of other columns) but the final display of those
#' columns is not necessary.
#'
#' @param data *The gt table data object*
#'
#' `obj:<gt_tbl>` // **required**
#'
#' This is the **gt** table object that is commonly created through use of the
#' [gt()] function.
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -128,7 +123,13 @@ cols_hide <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# if no `columns` are provided, return data unaltered
if (rlang::quo_is_missing(rlang::enquo(columns))) {
Expand Down Expand Up @@ -167,7 +168,7 @@ cols_hide <- function(
#' be important in cases where the user obtains a `gt_tbl` object with hidden
#' columns and there is motivation to reveal one or more of those.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -240,7 +241,13 @@ cols_unhide <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# Get the columns supplied in `columns` as a character vector
columns <-
Expand Down
10 changes: 8 additions & 2 deletions R/cols_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ cols_label <- function(
#' (with `.` representing the vector of column labels), or, an anonymous
#' function (e.g., `function(x) tools::toTitleCase(x)`).
#'
#' @inheritParams fmt_number
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -627,7 +627,13 @@ cols_label_with <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

fn <- rlang::as_function(fn)

Expand Down
40 changes: 32 additions & 8 deletions R/cols_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' columns (i.e., second and subsequent columns given in `columns`). The
#' formatting of values in different columns will be preserved upon merging.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -208,7 +208,13 @@ cols_merge <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# Get the columns supplied in `columns` as a character vector
columns <-
Expand Down Expand Up @@ -291,7 +297,7 @@ cols_merge <- function(
#' uncertainties, and any columns specified in `col_uncert` are hidden from
#' appearing the output table.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param col_val *Column to target for base values*
#'
Expand Down Expand Up @@ -420,7 +426,13 @@ cols_merge_uncert <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

resolved <-
cols_merge_resolver(
Expand Down Expand Up @@ -478,7 +490,7 @@ cols_merge_uncert <- function(
#' containing both values separated by an em dash. The column specified in
#' `col_end` is dropped from the output table.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param col_begin *Column to target for beginning of range*
#'
Expand Down Expand Up @@ -614,7 +626,13 @@ cols_merge_range <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

resolved <-
cols_merge_resolver(
Expand Down Expand Up @@ -691,7 +709,7 @@ cols_merge_range <- function(
#' percentages (e.g., `12 (23.2%)`). The column specified in `col_pct` is
#' dropped from the output table.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param col_n *Column to target for counts*
#'
Expand Down Expand Up @@ -824,7 +842,13 @@ cols_merge_n_pct <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

resolved <-
cols_merge_resolver(
Expand Down
30 changes: 24 additions & 6 deletions R/cols_move.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' `columns` to be moved is preserved, as is the ordering of all other columns
#' in the table.
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -110,7 +110,13 @@ cols_move <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# if no `columns` are provided, return data unaltered
if (rlang::quo_is_missing(rlang::enquo(columns))) {
Expand Down Expand Up @@ -185,7 +191,7 @@ cols_move <- function(
#' start is preserved (same with the ordering of all other columns in the
#' table).
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -261,7 +267,13 @@ cols_move_to_start <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# if no `columns` are provided, return data unaltered
if (rlang::quo_is_missing(rlang::enquo(columns))) {
Expand Down Expand Up @@ -311,7 +323,7 @@ cols_move_to_start <- function(
#' error prone. The ordering of the `columns` that are moved to the end is
#' preserved (same with the ordering of all other columns in the table).
#'
#' @inheritParams cols_hide
#' @inheritParams cols_align
#'
#' @param columns *Columns to target*
#'
Expand Down Expand Up @@ -387,7 +399,13 @@ cols_move_to_end <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = data)
stop_if_not_gt_tbl_or_group(data = data)

# Handle gt_group
if(inherits(data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(data, arg_list))
}

# if no `columns` are provided, return data unaltered
if (rlang::quo_is_missing(rlang::enquo(columns))) {
Expand Down
10 changes: 8 additions & 2 deletions R/cols_units.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' pertaining to the units notation can be found in the section entitled
#' *How to use **gt**'s units notation*.
#'
#' @inheritParams fmt_number
#' @inheritParams cols_align
#'
#' @param ... *Column units definitions*
#'
Expand Down Expand Up @@ -272,7 +272,13 @@ cols_units <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = .data)
stop_if_not_gt_tbl_or_group(data = .data)

# Handle gt_group
if(inherits(.data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(.data, arg_list))
}

# Collect a list of column units
units_list <- .list
Expand Down
10 changes: 8 additions & 2 deletions R/cols_width.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' left-hand side defines the target columns and the right-hand side is a single
#' dimension.
#'
#' @inheritParams fmt_number
#' @inheritParams cols_align
#'
#' @param ... *Column width assignments*
#'
Expand Down Expand Up @@ -112,7 +112,13 @@ cols_width <- function(
) {

# Perform input object validation
stop_if_not_gt_tbl(data = .data)
stop_if_not_gt_tbl_or_group(data = .data)

# Handle gt_group
if(inherits(.data, "gt_group")){
arg_list <- as.list(match.call())
return(apply_to_grp(.data, arg_list))
}

# Collect a named list of column widths
widths_list <- .list
Expand Down
Loading
Loading