From a58afb84711339f36bd0bf26a1f643930bc621af Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 25 May 2021 15:06:00 -0400 Subject: [PATCH 01/10] Complete 1st pass of `data` arg renaming --- R/gt.R | 10 +- R/modify_columns.R | 213 +++++++++--------- man/cols_align.Rd | 4 +- man/cols_hide.Rd | 4 +- man/cols_label.Rd | 4 +- man/cols_merge.Rd | 4 +- man/cols_merge_n_pct.Rd | 4 +- man/cols_merge_range.Rd | 4 +- man/cols_merge_uncert.Rd | 4 +- man/cols_move.Rd | 4 +- man/cols_move_to_end.Rd | 4 +- man/cols_move_to_start.Rd | 4 +- man/cols_unhide.Rd | 4 +- man/cols_width.Rd | 6 +- .../gt-examples/01-html-script/html-01-iris.R | 2 +- .../01-html-script/html-02-morley.R | 2 +- .../01-html-script/html-03-pressure.R | 2 +- .../01-html-script/html-04-sleep.R | 2 +- .../01-html-script/html-05-airquality.R | 2 +- .../html-09-formatting_uncertainties.R | 2 +- .../html-12-adding_spanner_column_labels.R | 2 +- .../gt-examples/02-html-rmd/html-01-iris.Rmd | 2 +- .../02-html-rmd/html-02-morley.Rmd | 2 +- .../02-html-rmd/html-03-pressure.Rmd | 2 +- .../gt-examples/02-html-rmd/html-04-sleep.Rmd | 2 +- .../02-html-rmd/html-05-airquality.Rmd | 2 +- .../html-09-formatting_uncertainties.Rmd | 2 +- .../html-12-adding_spanner_column_labels.Rmd | 2 +- tests/gt-examples/03-latex/latex-01-iris.Rmd | 2 +- .../gt-examples/03-latex/latex-02-morley.Rmd | 2 +- .../03-latex/latex-03-pressure.Rmd | 2 +- tests/gt-examples/03-latex/latex-04-sleep.Rmd | 2 +- .../03-latex/latex-05-airquality.Rmd | 2 +- .../latex-09-formatting_uncertainties.Rmd | 2 +- .../latex-12-adding_spanner_column_labels.Rmd | 2 +- tests/gt-examples/04-rtf/rtf_tests.R | 16 +- tests/testthat/test-cols_align.R | 16 +- tests/testthat/test-cols_move.R | 24 +- tests/testthat/test-conditional_fmt.R | 4 +- tests/testthat/test-fmt_bytes.R | 4 +- tests/testthat/test-fmt_currency.R | 19 +- tests/testthat/test-fmt_date_time.R | 38 +--- tests/testthat/test-fmt_missing.R | 11 +- tests/testthat/test-fmt_number.R | 18 +- tests/testthat/test-fmt_passthrough.R | 11 +- tests/testthat/test-fmt_percent.R | 5 +- tests/testthat/test-fmt_scientific.R | 17 +- tests/testthat/test-l_cols_align.R | 10 +- tests/testthat/test-l_cols_move.R | 14 +- tests/testthat/test-l_conditional_fmt.R | 10 +- tests/testthat/test-l_fmt_currency.R | 2 +- tests/testthat/test-l_fmt_date_time.R | 20 +- tests/testthat/test-l_fmt_missing.R | 5 +- tests/testthat/test-l_fmt_number.R | 2 +- tests/testthat/test-l_fmt_passthrough.R | 2 +- tests/testthat/test-l_fmt_percent.R | 2 +- tests/testthat/test-l_fmt_scientific.R | 2 +- tests/testthat/test-l_table_parts.R | 15 +- tests/testthat/test-r_table_parts.R | 2 +- tests/testthat/test-table_parts.R | 18 +- vignettes/intro-creating-gt-tables.Rmd | 4 +- 61 files changed, 265 insertions(+), 341 deletions(-) diff --git a/R/gt.R b/R/gt.R index 3124650d6..c3f014d3e 100644 --- a/R/gt.R +++ b/R/gt.R @@ -21,7 +21,7 @@ #' `row_group.sep` argument allows for control in how the row group label will #' appear in the display table. #' -#' @param data A `data.frame` object or a tibble. +#' @param .data A `data.frame` object or a tibble. #' @param rowname_col The column name in the input `data` table to use as row #' captions to be placed in the display table stub. If the `rownames_to_stub` #' option is `TRUE` then any column name provided to `rowname_col` will be @@ -83,9 +83,9 @@ #' 1-1 #' #' @export -gt <- function(data, +gt <- function(.data, rowname_col = "rowname", - groupname_col = dplyr::group_vars(data), + groupname_col = dplyr::group_vars(.data), caption = NULL, rownames_to_stub = FALSE, auto_align = TRUE, @@ -120,7 +120,7 @@ gt <- function(data, data <- dt_data_init( data = list(), - data_tbl = data, + data_tbl = .data, rownames_to_column = if (rownames_to_stub) rowname_col else NA_character_ ) @@ -177,7 +177,7 @@ gt <- function(data, # If automatic alignment of values is to be done, call # the `cols_align()` function on data if (auto_align) { - data <- cols_align(data = data, align = "auto") + data <- cols_align(.data = data, align = "auto") } data diff --git a/R/modify_columns.R b/R/modify_columns.R index a0eae3510..a9e71511a 100644 --- a/R/modify_columns.R +++ b/R/modify_columns.R @@ -14,7 +14,7 @@ #' center-alignment is for columns of class `logical`, `factor`, or `list`; and #' right-alignment is used for the `numeric` and `integer` columns. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' @param align The alignment type. This can be any of `"center"`, `"left"`, or #' `"right"` for center-, left-, or right-alignment. Alternatively, the #' `"auto"` option (the default), will automatically align values in columns @@ -49,15 +49,15 @@ #' 4-1 #' #' @export -cols_align <- function(data, +cols_align <- function(.data, align = c("auto", "left", "center", "right"), columns = everything()) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the internal data table - data_tbl <- dt_data_get(data = data) + data_tbl <- dt_data_get(data = .data) # Get the `align` value, this stops the function if there is no match align <- match.arg(align) @@ -66,7 +66,7 @@ cols_align <- function(data, column_names <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) if (align == "auto") { @@ -98,19 +98,21 @@ cols_align <- function(data, ) } else { + align <- rep(align, length(column_names)) } for (i in seq(column_names)) { - data <- + + .data <- dt_boxhead_edit( - data = data, + data = .data, var = column_names[i], column_align = align[i] ) } - data + .data } #' Set the widths of columns @@ -135,7 +137,7 @@ cols_align <- function(data, #' #' @inheritParams cols_align #' @param ... Expressions for the assignment of column widths for the table -#' columns in `data`. Two-sided formulas (e.g, ` ~ `) can be used, +#' columns in `.data`. Two-sided formulas (e.g, ` ~ `) can be used, #' where the left-hand side corresponds to selections of columns and the #' right-hand side evaluates to single-length character values in the form #' `{##}px` (i.e., pixel dimensions); the [px()] helper function is best used @@ -180,17 +182,17 @@ cols_align <- function(data, #' 4-2 #' #' @export -cols_width <- function(data, +cols_width <- function(.data, ..., .list = list2(...)) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Collect a named list of column widths widths_list <- .list - # If nothing is provided, return `data` unchanged + # If nothing is provided, return `.data` unchanged if (length(widths_list) == 0) { stop("Nothing was provided to `...`:\n", " * Use formula expressions to define custom column widths", @@ -224,7 +226,7 @@ cols_width <- function(data, columns <- resolve_cols_c( expr = !!cols, - data = data, + data = .data, excl_stub = FALSE ) %>% base::setdiff(columns_used) @@ -240,9 +242,10 @@ cols_width <- function(data, if (is.numeric(width)) width <- paste_right(as.character(width), "px") for (column in columns) { - data <- + + .data <- dt_boxhead_edit( - data = data, + data = .data, var = column, column_width = list(width) ) @@ -250,27 +253,27 @@ cols_width <- function(data, } unset_widths <- - dt_boxhead_get(data = data) %>% + dt_boxhead_get(data = .data) %>% .$column_width %>% lapply(is.null) %>% unlist() if (any(unset_widths)) { - columns_unset <- dt_boxhead_get_vars(data = data)[unset_widths] + columns_unset <- dt_boxhead_get_vars(data = .data)[unset_widths] for (column in columns_unset) { - data <- + .data <- dt_boxhead_edit( - data = data, + data = .data, var = column, column_width = list("") ) } } - data + .data } #' Relabel one or more columns @@ -347,19 +350,19 @@ cols_width <- function(data, #' #' @import rlang #' @export -cols_label <- function(data, +cols_label <- function(.data, ..., .list = list2(...)) { - # Perform input object validation - stop_if_not_gt(data = data) - # Collect a named list of column labels labels_list <- .list + # Perform input object validation + stop_if_not_gt(data = .data) + # If nothing is provided, return `data` unchanged if (length(labels_list) == 0) { - return(data) + return(.data) } # Test for names being NULL @@ -373,32 +376,32 @@ cols_label <- function(data, } # Stop function if any of the column names specified are not in `cols_labels` - if (!all(names(labels_list) %in% dt_boxhead_get_vars(data = data))) { - stop("All column names provided must exist in the input `data` table.") + if (!all(names(labels_list) %in% dt_boxhead_get_vars(data = .data))) { + stop("All column names provided must exist in the input `.data` table.") } # Filter the list of labels by the var names in `data` labels_list <- - labels_list[names(labels_list) %in% dt_boxhead_get_vars(data = data)] + labels_list[names(labels_list) %in% dt_boxhead_get_vars(data = .data)] # If no labels remain after filtering, return the data if (length(labels_list) == 0) { - return(data) + return(.data) } nm_labels_list <- names(labels_list) for (i in seq_along(labels_list)) { - data <- + .data <- dt_boxhead_edit_column_label( - data = data, + data = .data, var = nm_labels_list[i], column_label = labels_list[[i]] ) } - data + .data } #' Move one or more columns to the start @@ -463,19 +466,19 @@ cols_label <- function(data, #' #' @import rlang #' @export -cols_move_to_start <- function(data, +cols_move_to_start <- function(.data, columns) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - vars <- dt_boxhead_get_vars(data = data) + vars <- dt_boxhead_get_vars(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) # Stop function if no `columns` are provided @@ -485,7 +488,7 @@ cols_move_to_start <- function(data, # Stop function if any of the `columns` don't exist in `vars` if (!all(columns %in% vars)) { - stop("All `columns` must exist and be visible in the input `data` table.", + stop("All `columns` must exist and be visible in the input `.data` table.", call. = FALSE) } @@ -494,9 +497,9 @@ cols_move_to_start <- function(data, new_vars <- append(other_columns, columns, after = 0) - data <- dt_boxhead_set_var_order(data = data, vars = new_vars) + .data <- dt_boxhead_set_var_order(data = .data, vars = new_vars) - data + .data } #' Move one or more columns to the end @@ -560,19 +563,19 @@ cols_move_to_start <- function(data, #' #' @import rlang #' @export -cols_move_to_end <- function(data, +cols_move_to_end <- function(.data, columns) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - vars <- dt_boxhead_get_vars(data = data) + vars <- dt_boxhead_get_vars(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) # Stop function if no `columns` are provided @@ -582,7 +585,7 @@ cols_move_to_end <- function(data, # Stop function if any of the `columns` don't exist in `vars` if (!all(columns %in% vars)) { - stop("All `columns` must exist and be visible in the input `data` table.", + stop("All `columns` must exist and be visible in the input `.data` table.", call. = FALSE) } @@ -591,9 +594,9 @@ cols_move_to_end <- function(data, new_vars <- append(other_columns, columns) - data <- dt_boxhead_set_var_order(data = data, vars = new_vars) + .data <- dt_boxhead_set_var_order(data = .data, vars = new_vars) - data + .data } #' Move one or more columns @@ -648,28 +651,28 @@ cols_move_to_end <- function(data, #' #' @import rlang #' @export -cols_move <- function(data, +cols_move <- function(.data, columns, after) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) # Get the `after` columns as a character vector after <- resolve_cols_c( expr = {{ after }}, - data = data + data = .data ) - vars <- dt_boxhead_get_vars(data = data) + vars <- dt_boxhead_get_vars(data = .data) # Stop function if `after` contains multiple columns if (length(after) > 1) { @@ -679,7 +682,7 @@ cols_move <- function(data, # Stop function if `after` doesn't exist in `vars` if (!(after %in% vars)) { - stop("The column supplied to `after` doesn't exist in the input `data` table.", + stop("The column supplied to `after` doesn't exist in the input `.data` table.", call. = FALSE) } @@ -690,7 +693,7 @@ cols_move <- function(data, # Stop function if any of the `columns` don't exist in `vars` if (!all(columns %in% vars)) { - stop("All `columns` must exist and be visible in the input `data` table.", + stop("All `columns` must exist and be visible in the input `.data` table.", call. = FALSE) } @@ -704,9 +707,9 @@ cols_move <- function(data, new_vars <- append(other_columns, moving_columns, after = after_index) - data <- dt_boxhead_set_var_order(data = data, vars = new_vars) + .data <- dt_boxhead_set_var_order(data = .data, vars = new_vars) - data + .data } #' Hide one or more columns @@ -784,20 +787,20 @@ cols_move <- function(data, #' #' @import rlang #' @export -cols_hide <- function(data, +cols_hide <- function(.data, columns) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) - vars <- dt_boxhead_get_vars(data = data) + vars <- dt_boxhead_get_vars(data = .data) # Stop function if no `columns` are provided if (length(columns) == 0) { @@ -806,14 +809,14 @@ cols_hide <- function(data, # Stop function if any of the `columns` don't exist in `vars` if (!all(columns %in% vars)) { - stop("All `columns` must exist in the input `data` table.", + stop("All `columns` must exist in the input `.data` table.", call. = FALSE) } # Set the `"hidden"` type for the `columns` in `_dt_boxhead` - data <- dt_boxhead_set_hidden(data = data, vars = columns) + .data <- dt_boxhead_set_hidden(data = .data, vars = columns) - data + .data } #' Unhide one or more columns @@ -877,20 +880,20 @@ cols_hide <- function(data, #' #' @import rlang #' @export -cols_unhide <- function(data, +cols_unhide <- function(.data, columns) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) - vars <- dt_boxhead_get_vars(data = data) + vars <- dt_boxhead_get_vars(data = .data) # Stop function if no `columns` are provided if (length(columns) == 0) { @@ -899,14 +902,14 @@ cols_unhide <- function(data, # Stop function if any of the `columns` don't exist in `vars` if (!all(columns %in% vars)) { - stop("All `columns` must exist in the input `data` table.", + stop("All `columns` must exist in the input `.data` table.", call. = FALSE) } # Set the `"visible"` type for the `columns` in `_dt_boxhead` - data <- dt_boxhead_set_not_hidden(data = data, vars = columns) + .data <- dt_boxhead_set_not_hidden(data = .data, vars = columns) - data + .data } #' Merge two columns to a value & uncertainty column @@ -994,27 +997,27 @@ cols_unhide <- function(data, #' #' @import rlang #' @export -cols_merge_uncert <- function(data, +cols_merge_uncert <- function(.data, col_val, col_uncert, sep = " +/- ", autohide = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) resolved <- cols_merge_resolver( - data = data, + data = .data, col_begin = {{ col_val }}, col_end = {{ col_uncert }}, sep = sep ) # Create an entry and add it to the `_col_merge` attribute - data <- + .data <- dt_col_merge_add( - data = data, + data = .data, col_merge = dt_col_merge_entry( vars = resolved$columns, type = "merge_uncert", @@ -1028,13 +1031,13 @@ cols_merge_uncert <- function(data, col_uncert <- resolve_cols_c( expr = {{ col_uncert }}, - data = data + data = .data ) - data <- cols_hide(data = data, columns = col_uncert) + .data <- cols_hide(.data = .data, columns = col_uncert) } - data + .data } #' Merge two columns to a value range column @@ -1114,27 +1117,27 @@ cols_merge_uncert <- function(data, #' #' @import rlang #' @export -cols_merge_range <- function(data, +cols_merge_range <- function(.data, col_begin, col_end, sep = "--", autohide = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) resolved <- cols_merge_resolver( - data = data, + data = .data, col_begin = {{ col_begin }}, col_end = {{ col_end }}, sep = sep ) # Create an entry and add it to the `_col_merge` attribute - data <- + .data <- dt_col_merge_add( - data = data, + data = .data, col_merge = dt_col_merge_entry( vars = resolved$columns, type = "merge_range", @@ -1148,13 +1151,13 @@ cols_merge_range <- function(data, col_end <- resolve_cols_c( expr = {{ col_end }}, - data = data + data = .data ) - data <- cols_hide(data = data, columns = col_end) + .data <- cols_hide(.data = .data, columns = col_end) } - data + .data } cols_merge_resolver <- function(data, col_begin, col_end, sep) { @@ -1281,26 +1284,26 @@ cols_merge_resolver <- function(data, col_begin, col_end, sep) { #' #' @import rlang #' @export -cols_merge_n_pct <- function(data, +cols_merge_n_pct <- function(.data, col_n, col_pct, autohide = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) resolved <- cols_merge_resolver( - data = data, + data = .data, col_begin = {{ col_n }}, col_end = {{ col_pct }}, sep = "" ) # Create an entry and add it to the `_col_merge` attribute - data <- + .data <- dt_col_merge_add( - data = data, + data = .data, col_merge = dt_col_merge_entry( vars = resolved$columns, type = "merge_n_pct", @@ -1314,13 +1317,13 @@ cols_merge_n_pct <- function(data, col_pct <- resolve_cols_c( expr = {{ col_pct }}, - data = data + data = .data ) - data <- data %>% cols_hide(columns = col_pct) + .data <- cols_hide(.data = .data, columns = col_pct) } - data + .data } #' Merge data from two or more columns to a single column @@ -1392,19 +1395,19 @@ cols_merge_n_pct <- function(data, #' #' @import rlang #' @export -cols_merge <- function(data, +cols_merge <- function(.data, columns, hide_columns = columns[-1], pattern = paste0("{", seq_along(columns), "}", collapse = " ")) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) # NOTE: It's important that `hide_columns` NOT be evaluated until after the @@ -1418,7 +1421,7 @@ cols_merge <- function(data, hide_columns <- resolve_cols_c( expr = {{ hide_columns }}, - data = data + data = .data ) ) @@ -1427,20 +1430,22 @@ cols_merge <- function(data, hide_columns_from_supplied <- base::intersect(hide_columns, columns) if (length(base::setdiff(hide_columns, columns) > 0)) { - warning("Only the columns supplied in `columns` will be hidden.\n", - " * use `cols_hide()` to hide any out of scope columns", - call. = FALSE) + warning( + "Only the columns supplied in `columns` will be hidden.\n", + " * use `cols_hide()` to hide any out of scope columns", + call. = FALSE + ) } if (length(hide_columns_from_supplied) > 0) { - data <- cols_hide(data = data, columns = hide_columns_from_supplied) + .data <- cols_hide(.data = .data, columns = hide_columns_from_supplied) } } # Create an entry and add it to the `_col_merge` attribute - data <- + .data <- dt_col_merge_add( - data = data, + data = .data, col_merge = dt_col_merge_entry( vars = columns, type = "merge", @@ -1448,5 +1453,5 @@ cols_merge <- function(data, ) ) - data + .data } diff --git a/man/cols_align.Rd b/man/cols_align.Rd index ea27eb98e..ed2d69208 100644 --- a/man/cols_align.Rd +++ b/man/cols_align.Rd @@ -5,13 +5,13 @@ \title{Set the alignment of columns} \usage{ cols_align( - data, + .data, align = c("auto", "left", "center", "right"), columns = everything() ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{align}{The alignment type. This can be any of \code{"center"}, \code{"left"}, or \code{"right"} for center-, left-, or right-alignment. Alternatively, the diff --git a/man/cols_hide.Rd b/man/cols_hide.Rd index 2f11c7fa0..d0aac8439 100644 --- a/man/cols_hide.Rd +++ b/man/cols_hide.Rd @@ -4,10 +4,10 @@ \alias{cols_hide} \title{Hide one or more columns} \usage{ -cols_hide(data, columns) +cols_hide(.data, columns) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The column names to hide from the output display table. Values provided that do not correspond to column names will be disregarded.} diff --git a/man/cols_label.Rd b/man/cols_label.Rd index e5c0a8224..78e94bafb 100644 --- a/man/cols_label.Rd +++ b/man/cols_label.Rd @@ -4,10 +4,10 @@ \alias{cols_label} \title{Relabel one or more columns} \usage{ -cols_label(data, ..., .list = list2(...)) +cols_label(.data, ..., .list = list2(...)) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{...}{One or more named arguments of column names from the input \code{data} table along with their labels for display as the column labels. We can diff --git a/man/cols_merge.Rd b/man/cols_merge.Rd index ff6f5fce3..60d7914ab 100644 --- a/man/cols_merge.Rd +++ b/man/cols_merge.Rd @@ -5,14 +5,14 @@ \title{Merge data from two or more columns to a single column} \usage{ cols_merge( - data, + .data, columns, hide_columns = columns[-1], pattern = paste0("{", seq_along(columns), "}", collapse = " ") ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns that will participate in the merging process. The first column name provided will be the target column (i.e., undergo diff --git a/man/cols_merge_n_pct.Rd b/man/cols_merge_n_pct.Rd index 6943b49e6..b21250b8f 100644 --- a/man/cols_merge_n_pct.Rd +++ b/man/cols_merge_n_pct.Rd @@ -4,10 +4,10 @@ \alias{cols_merge_n_pct} \title{Merge two columns to combine counts and percentages} \usage{ -cols_merge_n_pct(data, col_n, col_pct, autohide = TRUE) +cols_merge_n_pct(.data, col_n, col_pct, autohide = TRUE) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{col_n}{A column that contains values for the count component.} diff --git a/man/cols_merge_range.Rd b/man/cols_merge_range.Rd index a85dcfdda..897759a70 100644 --- a/man/cols_merge_range.Rd +++ b/man/cols_merge_range.Rd @@ -4,10 +4,10 @@ \alias{cols_merge_range} \title{Merge two columns to a value range column} \usage{ -cols_merge_range(data, col_begin, col_end, sep = "--", autohide = TRUE) +cols_merge_range(.data, col_begin, col_end, sep = "--", autohide = TRUE) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{col_begin}{A column that contains values for the start of the range.} diff --git a/man/cols_merge_uncert.Rd b/man/cols_merge_uncert.Rd index a6c127e79..e361e9289 100644 --- a/man/cols_merge_uncert.Rd +++ b/man/cols_merge_uncert.Rd @@ -4,10 +4,10 @@ \alias{cols_merge_uncert} \title{Merge two columns to a value & uncertainty column} \usage{ -cols_merge_uncert(data, col_val, col_uncert, sep = " +/- ", autohide = TRUE) +cols_merge_uncert(.data, col_val, col_uncert, sep = " +/- ", autohide = TRUE) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{col_val}{A single column name that contains the base values. This is the column where values will be mutated.} diff --git a/man/cols_move.Rd b/man/cols_move.Rd index f72ed5282..8b9d0689c 100644 --- a/man/cols_move.Rd +++ b/man/cols_move.Rd @@ -4,10 +4,10 @@ \alias{cols_move} \title{Move one or more columns} \usage{ -cols_move(data, columns, after) +cols_move(.data, columns, after) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The column names to move to as a group to a different position. The order of the remaining columns will be preserved.} diff --git a/man/cols_move_to_end.Rd b/man/cols_move_to_end.Rd index 445a81009..77616a190 100644 --- a/man/cols_move_to_end.Rd +++ b/man/cols_move_to_end.Rd @@ -4,10 +4,10 @@ \alias{cols_move_to_end} \title{Move one or more columns to the end} \usage{ -cols_move_to_end(data, columns) +cols_move_to_end(.data, columns) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The column names to move to the right-most side of the table. The order in which columns are provided will be preserved (as is the case diff --git a/man/cols_move_to_start.Rd b/man/cols_move_to_start.Rd index a3e2eac4c..08d8cb247 100644 --- a/man/cols_move_to_start.Rd +++ b/man/cols_move_to_start.Rd @@ -4,10 +4,10 @@ \alias{cols_move_to_start} \title{Move one or more columns to the start} \usage{ -cols_move_to_start(data, columns) +cols_move_to_start(.data, columns) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The column names to move to the left-most side of the table. The order in which columns are provided will be preserved (as is the case diff --git a/man/cols_unhide.Rd b/man/cols_unhide.Rd index a24fbfd53..2878411d9 100644 --- a/man/cols_unhide.Rd +++ b/man/cols_unhide.Rd @@ -4,10 +4,10 @@ \alias{cols_unhide} \title{Unhide one or more columns} \usage{ -cols_unhide(data, columns) +cols_unhide(.data, columns) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The column names to unhide from the output display table. Values provided that do not correspond to column names will be disregarded.} diff --git a/man/cols_width.Rd b/man/cols_width.Rd index b510eeb42..19ea646ba 100644 --- a/man/cols_width.Rd +++ b/man/cols_width.Rd @@ -4,13 +4,13 @@ \alias{cols_width} \title{Set the widths of columns} \usage{ -cols_width(data, ..., .list = list2(...)) +cols_width(.data, ..., .list = list2(...)) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{...}{Expressions for the assignment of column widths for the table -columns in \code{data}. Two-sided formulas (e.g, \verb{ ~ }) can be used, +columns in \code{.data}. Two-sided formulas (e.g, \verb{ ~ }) can be used, where the left-hand side corresponds to selections of columns and the right-hand side evaluates to single-length character values in the form \verb{\{##\}px} (i.e., pixel dimensions); the \code{\link[=px]{px()}} helper function is best used diff --git a/tests/gt-examples/01-html-script/html-01-iris.R b/tests/gt-examples/01-html-script/html-01-iris.R index 300b8a67d..6c99ca177 100644 --- a/tests/gt-examples/01-html-script/html-01-iris.R +++ b/tests/gt-examples/01-html-script/html-01-iris.R @@ -2,7 +2,7 @@ library(gt) # Create a display table based on `iris` iris_tbl <- - gt(data = iris) %>% + gt(iris) %>% tab_spanner_delim(delim = ".") %>% cols_move_to_start(columns = Species) %>% fmt_number( diff --git a/tests/gt-examples/01-html-script/html-02-morley.R b/tests/gt-examples/01-html-script/html-02-morley.R index eda6c76d8..80d9630a6 100644 --- a/tests/gt-examples/01-html-script/html-02-morley.R +++ b/tests/gt-examples/01-html-script/html-02-morley.R @@ -2,7 +2,7 @@ library(gt) # Create a display table based on `morley` morley_tbl <- - gt(data = morley) %>% + gt(morley) %>% fmt_number( columns = Speed, decimals = 0, diff --git a/tests/gt-examples/01-html-script/html-03-pressure.R b/tests/gt-examples/01-html-script/html-03-pressure.R index a8076f55a..95d82b34c 100644 --- a/tests/gt-examples/01-html-script/html-03-pressure.R +++ b/tests/gt-examples/01-html-script/html-03-pressure.R @@ -2,7 +2,7 @@ library(gt) # Create a display table based on `pressure` pressure_tbl <- - gt(data = pressure) %>% + gt(pressure) %>% fmt_scientific( columns = pressure, decimals = 2 diff --git a/tests/gt-examples/01-html-script/html-04-sleep.R b/tests/gt-examples/01-html-script/html-04-sleep.R index 7ef312544..3a3b8505c 100644 --- a/tests/gt-examples/01-html-script/html-04-sleep.R +++ b/tests/gt-examples/01-html-script/html-04-sleep.R @@ -2,7 +2,7 @@ library(gt) # Create a display table based on `sleep` sleep_tbl <- - gt(data = sleep) %>% + gt(sleep) %>% fmt_scientific(columns = extra) %>% tab_footnote( footnote = "This is a footnote", diff --git a/tests/gt-examples/01-html-script/html-05-airquality.R b/tests/gt-examples/01-html-script/html-05-airquality.R index 5e035d6b6..cf4ede0ce 100644 --- a/tests/gt-examples/01-html-script/html-05-airquality.R +++ b/tests/gt-examples/01-html-script/html-05-airquality.R @@ -2,7 +2,7 @@ library(gt) # Create a display table based on `airquality` airquality_tbl <- - gt(data = airquality) %>% + gt(airquality) %>% cols_move_to_start(columns = c(Month, Day)) %>% cols_label(Solar.R = html("Solar
Radiation")) %>% fmt_number( diff --git a/tests/gt-examples/01-html-script/html-09-formatting_uncertainties.R b/tests/gt-examples/01-html-script/html-09-formatting_uncertainties.R index bc0ba67bd..fd7ecfec7 100644 --- a/tests/gt-examples/01-html-script/html-09-formatting_uncertainties.R +++ b/tests/gt-examples/01-html-script/html-09-formatting_uncertainties.R @@ -13,7 +13,7 @@ tbl <- # Create a display table with uncertainties uncert_tbl <- - gt(data = tbl) %>% + gt(tbl) %>% cols_merge_uncert( col_val = value_1, col_uncert = uncertainty diff --git a/tests/gt-examples/01-html-script/html-12-adding_spanner_column_labels.R b/tests/gt-examples/01-html-script/html-12-adding_spanner_column_labels.R index 79b9fad35..a45557d72 100644 --- a/tests/gt-examples/01-html-script/html-12-adding_spanner_column_labels.R +++ b/tests/gt-examples/01-html-script/html-12-adding_spanner_column_labels.R @@ -12,7 +12,7 @@ tbl <- # Create a display table gt_tbl <- - gt(data = tbl) %>% + gt(tbl) %>% tab_spanner( label = "v_1_2", columns = c(v_1, v_2) diff --git a/tests/gt-examples/02-html-rmd/html-01-iris.Rmd b/tests/gt-examples/02-html-rmd/html-01-iris.Rmd index ce1ba4ab8..f64eb3eb3 100644 --- a/tests/gt-examples/02-html-rmd/html-01-iris.Rmd +++ b/tests/gt-examples/02-html-rmd/html-01-iris.Rmd @@ -13,7 +13,7 @@ library(gt) Create a display table based on `iris`. ```{r} -gt(data = iris) %>% +gt(iris) %>% tab_spanner_delim(delim = ".") %>% cols_move_to_start(columns = Species) %>% fmt_number( diff --git a/tests/gt-examples/02-html-rmd/html-02-morley.Rmd b/tests/gt-examples/02-html-rmd/html-02-morley.Rmd index 88b8ba73a..96198c1c4 100644 --- a/tests/gt-examples/02-html-rmd/html-02-morley.Rmd +++ b/tests/gt-examples/02-html-rmd/html-02-morley.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `morley`. ```{r} -gt(data = morley) %>% +gt(morley) %>% fmt_number( columns = Speed, decimals = 0, diff --git a/tests/gt-examples/02-html-rmd/html-03-pressure.Rmd b/tests/gt-examples/02-html-rmd/html-03-pressure.Rmd index 5554bdde0..271fa78fe 100644 --- a/tests/gt-examples/02-html-rmd/html-03-pressure.Rmd +++ b/tests/gt-examples/02-html-rmd/html-03-pressure.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `pressure`. ```{r} - gt(data = pressure) %>% +gt(pressure) %>% fmt_scientific( columns = pressure, decimals = 2 diff --git a/tests/gt-examples/02-html-rmd/html-04-sleep.Rmd b/tests/gt-examples/02-html-rmd/html-04-sleep.Rmd index e9505fca9..037d0102e 100644 --- a/tests/gt-examples/02-html-rmd/html-04-sleep.Rmd +++ b/tests/gt-examples/02-html-rmd/html-04-sleep.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `sleep`. ```{r} -gt(data = sleep) %>% +gt(sleep) %>% fmt_scientific(columns = extra) %>% tab_footnote( footnote = "This is a footnote", diff --git a/tests/gt-examples/02-html-rmd/html-05-airquality.Rmd b/tests/gt-examples/02-html-rmd/html-05-airquality.Rmd index 1770696f3..486555a28 100644 --- a/tests/gt-examples/02-html-rmd/html-05-airquality.Rmd +++ b/tests/gt-examples/02-html-rmd/html-05-airquality.Rmd @@ -13,7 +13,7 @@ library(gt) Create a display table based on `airquality`. ```{r} -gt(data = airquality) %>% +gt(airquality) %>% cols_move_to_start(columns = c(Month, Day)) %>% cols_label(Solar.R = html("Solar
Radiation")) %>% fmt_number( diff --git a/tests/gt-examples/02-html-rmd/html-09-formatting_uncertainties.Rmd b/tests/gt-examples/02-html-rmd/html-09-formatting_uncertainties.Rmd index 9712c27dc..ef3ffab4b 100644 --- a/tests/gt-examples/02-html-rmd/html-09-formatting_uncertainties.Rmd +++ b/tests/gt-examples/02-html-rmd/html-09-formatting_uncertainties.Rmd @@ -25,7 +25,7 @@ tbl <- ``` ```{r} -gt(data = tbl) %>% +gt(tbl) %>% cols_merge_uncert( col_val = value_1, col_uncert = uncertainty diff --git a/tests/gt-examples/02-html-rmd/html-12-adding_spanner_column_labels.Rmd b/tests/gt-examples/02-html-rmd/html-12-adding_spanner_column_labels.Rmd index d805eb82b..254bd0c1c 100644 --- a/tests/gt-examples/02-html-rmd/html-12-adding_spanner_column_labels.Rmd +++ b/tests/gt-examples/02-html-rmd/html-12-adding_spanner_column_labels.Rmd @@ -24,7 +24,7 @@ tbl <- ``` ```{r} -gt(data = tbl) %>% +gt(tbl) %>% tab_spanner( label = "v_1_2", columns = c(v_1, v_2) diff --git a/tests/gt-examples/03-latex/latex-01-iris.Rmd b/tests/gt-examples/03-latex/latex-01-iris.Rmd index f21e9f6e8..626f0f2d1 100644 --- a/tests/gt-examples/03-latex/latex-01-iris.Rmd +++ b/tests/gt-examples/03-latex/latex-01-iris.Rmd @@ -13,7 +13,7 @@ library(gt) Create a display table based on `iris` Edgar Anderson's Iris Data. ```{r} -gt(data = iris) %>% +gt(iris) %>% tab_spanner_delim(delim = ".") %>% cols_move_to_start(columns = Species) %>% fmt_number( diff --git a/tests/gt-examples/03-latex/latex-02-morley.Rmd b/tests/gt-examples/03-latex/latex-02-morley.Rmd index 33de93908..209c13a68 100644 --- a/tests/gt-examples/03-latex/latex-02-morley.Rmd +++ b/tests/gt-examples/03-latex/latex-02-morley.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `morley` Michelson Speed of Light Data ```{r} -gt(data = morley %>% dplyr::mutate(Speed = as.numeric(Speed))) %>% +gt(morley %>% dplyr::mutate(Speed = as.numeric(Speed))) %>% fmt_number( columns = Speed, decimals = 0, diff --git a/tests/gt-examples/03-latex/latex-03-pressure.Rmd b/tests/gt-examples/03-latex/latex-03-pressure.Rmd index 32495ae87..3a661eda7 100644 --- a/tests/gt-examples/03-latex/latex-03-pressure.Rmd +++ b/tests/gt-examples/03-latex/latex-03-pressure.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `pressure`. ```{r} -gt(data = pressure) %>% +gt(pressure) %>% fmt_scientific( columns = pressure, decimals = 2 diff --git a/tests/gt-examples/03-latex/latex-04-sleep.Rmd b/tests/gt-examples/03-latex/latex-04-sleep.Rmd index 3d26abf7c..2cee6ca3d 100644 --- a/tests/gt-examples/03-latex/latex-04-sleep.Rmd +++ b/tests/gt-examples/03-latex/latex-04-sleep.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `sleep`. ```{r} -gt(data = sleep) %>% +gt(sleep) %>% fmt_scientific(columns = extra) %>% tab_footnote( footnote = "This is a footnote", diff --git a/tests/gt-examples/03-latex/latex-05-airquality.Rmd b/tests/gt-examples/03-latex/latex-05-airquality.Rmd index c16fae20b..01e4956d6 100644 --- a/tests/gt-examples/03-latex/latex-05-airquality.Rmd +++ b/tests/gt-examples/03-latex/latex-05-airquality.Rmd @@ -12,7 +12,7 @@ library(gt) Create a display table based on `airquality`. ```{r} -gt(data = airquality) %>% +gt(airquality) %>% cols_move_to_start(columns = c(Month, Day)) %>% fmt_number( columns = Wind, diff --git a/tests/gt-examples/03-latex/latex-09-formatting_uncertainties.Rmd b/tests/gt-examples/03-latex/latex-09-formatting_uncertainties.Rmd index 59cc3f7a1..eaacbbcf3 100644 --- a/tests/gt-examples/03-latex/latex-09-formatting_uncertainties.Rmd +++ b/tests/gt-examples/03-latex/latex-09-formatting_uncertainties.Rmd @@ -26,7 +26,7 @@ tbl <- ```{r} -gt(data = tbl) %>% +gt(tbl) %>% cols_merge_uncert( col_val = value_1, col_uncert = uncertainty diff --git a/tests/gt-examples/03-latex/latex-12-adding_spanner_column_labels.Rmd b/tests/gt-examples/03-latex/latex-12-adding_spanner_column_labels.Rmd index cc19b6cf4..329db2fd0 100644 --- a/tests/gt-examples/03-latex/latex-12-adding_spanner_column_labels.Rmd +++ b/tests/gt-examples/03-latex/latex-12-adding_spanner_column_labels.Rmd @@ -24,7 +24,7 @@ tbl <- ``` ```{r} -gt(data = tbl) %>% +gt(tbl) %>% tab_spanner( label = "v_1_2", columns = c(v_1, v_2) diff --git a/tests/gt-examples/04-rtf/rtf_tests.R b/tests/gt-examples/04-rtf/rtf_tests.R index 02aeee57e..32a3f5dab 100644 --- a/tests/gt-examples/04-rtf/rtf_tests.R +++ b/tests/gt-examples/04-rtf/rtf_tests.R @@ -35,7 +35,7 @@ unicode_tbl %>% gtsave("tests/gt-examples/rtf_output/unicode.rtf") # Create a display table based on `iris` iris_tbl <- - gt(data = iris) %>% + gt(iris) %>% tab_spanner_delim(delim = ".") %>% cols_move_to_start(columns = Species) %>% fmt_number( @@ -71,7 +71,7 @@ passthrough_tbl %>% gtsave("tests/gt-examples/rtf_output/passthrough.rtf") # Create a display table based on `morley` morley_tbl <- - gt(data = morley) %>% + gt(morley) %>% fmt_number( columns = Speed, decimals = 0, @@ -82,7 +82,7 @@ morley_tbl %>% gtsave("tests/gt-examples/rtf_output/morley.rtf") # Create a display table based on `pressure` pressure_tbl <- - gt(data = pressure) %>% + gt(pressure) %>% fmt_scientific( columns = pressure, decimals = 2 @@ -92,7 +92,7 @@ pressure_tbl %>% gtsave("tests/gt-examples/rtf_output/pressure.rtf") # Create a display table based on `sleep` sleep_tbl <- - gt(data = sleep) %>% + gt(sleep) %>% fmt_scientific(columns = extra) %>% tab_footnote( footnote = "This is a footnote", @@ -103,7 +103,7 @@ sleep_tbl %>% gtsave("tests/gt-examples/rtf_output/sleep.rtf") # Create a display table based on `airquality` airquality_tbl <- - gt(data = airquality) %>% + gt(airquality) %>% cols_move_to_start(columns = c(Month, Day)) %>% cols_label(Solar.R = md("Solar \nRadiation")) %>% fmt_number( @@ -212,7 +212,7 @@ tbl <- # Create a display table with uncertainties uncert_tbl <- - gt(data = tbl) %>% + gt(tbl) %>% cols_merge_uncert( col_val = value_1, col_uncert = uncertainty @@ -299,7 +299,7 @@ tbl <- # Create a display table footnotes_tbl <- - gt(data = tbl, groupname_col = "date") %>% + gt(tbl, groupname_col = "date") %>% tab_header(title = md("The Table `Title`"), subtitle = "The subtitle.") %>% tab_spanner( label = "values", @@ -355,7 +355,7 @@ tbl <- # Create a display table spanner_tbl <- - gt(data = tbl) %>% + gt(tbl) %>% tab_spanner( label = "v_1_2", columns = c("v_1", "v_2") diff --git a/tests/testthat/test-cols_align.R b/tests/testthat/test-cols_align.R index 07bfb8593..908765d93 100644 --- a/tests/testthat/test-cols_align.R +++ b/tests/testthat/test-cols_align.R @@ -23,7 +23,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns are aligned left tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = c(mpg, cyl, drat)) %>% render_as_html() %>% xml2::read_html() @@ -44,7 +44,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_html` object with `gt()`; columns `1` (`mpg`), # `2` (`cyl`), and `3` (`disp`) are aligned left tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = 1:3) %>% render_as_html() %>% xml2::read_html() @@ -65,25 +65,25 @@ test_that("the `cols_align()` function works correctly", { # Expect that supplying an `align` value that is not `left`, `center`, # or `right` will result in an error expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "righter", columns = c(mpg, cyl, drat))) # Expect that supplying a column name that doesn't exist in the # table columns will result in an error expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "right", columns = car)) # Expect that supplying any column index that doesn't exist in the # table will result in an error expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "right", columns = c(1, 20))) # Create a `tbl_html` object with `gt()`; align all # columns to the left tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left") %>% render_as_html() %>% xml2::read_html() @@ -98,7 +98,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_html` object with `gt()`; align all # columns (using `columns = everything()`) to the left tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = everything()) %>% render_as_html() %>% xml2::read_html() @@ -113,7 +113,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_html` object with the `sp500` data # frame and `auto`-align all columns tbl_html <- - gt(data = sp500) %>% + gt(sp500) %>% cols_align(align = "auto") %>% render_as_html() %>% xml2::read_html() diff --git a/tests/testthat/test-cols_move.R b/tests/testthat/test-cols_move.R index 415b08af7..27fb39f43 100644 --- a/tests/testthat/test-cols_move.R +++ b/tests/testthat/test-cols_move.R @@ -17,7 +17,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `drat` tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = drat) # Expect a particular ordering of columns in `_boxh` @@ -41,7 +41,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `drat` using vectors tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c("mpg", "cyl", "disp"), after = c("drat")) # Expect a particular ordering of columns in `_boxh` @@ -65,7 +65,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `carb` (the end of the series) tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = carb) # Expect a particular ordering of columns in the internal `boxh_df` @@ -88,17 +88,17 @@ test_that("the `cols_move()` function works correctly", { # Expect an error if more than one column provided in `after` expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = c(am, wt))) # Expect an error if the column provided in `after` doesn't exist expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = wts)) # Expect an error if any of the `columns` doesn't exist in `data_df` expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyls, disp), after = wt)) }) @@ -110,7 +110,7 @@ test_that("the `cols_move_to_start()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `gear`, # and `carb` columns placed at the start tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_start(columns = c(gear, carb)) # Expect a particular ordering of columns in the internal `boxh_df` @@ -134,7 +134,7 @@ test_that("the `cols_move_to_start()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `gear`, # and `carb` columns placed at the start using vectors tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_start(columns = c("gear", "carb")) # Expect a particular ordering of columns in the internal `boxh_df` @@ -157,7 +157,7 @@ test_that("the `cols_move_to_start()` function works correctly", { # Expect an error if any of the `columns` doesn't exist in `data_df` expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_start(columns = c(mpg, cyls, disp))) }) @@ -169,7 +169,7 @@ test_that("the `cols_move_to_end()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `gear`, # and `carb` columns placed at the end tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_end(columns = c(gear, carb)) # Expect a particular ordering of columns in the internal `boxh_df` @@ -193,7 +193,7 @@ test_that("the `cols_move_to_end()` function works correctly", { # Create a `tbl_html` object with `gt()`; the `gear`, # and `carb` columns placed at the start using vectors tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_end(columns = c("gear", "carb")) # Expect a particular ordering of columns in the internal `boxh_df` @@ -216,6 +216,6 @@ test_that("the `cols_move_to_end()` function works correctly", { # Expect an error if any of the `columns` doesn't exist in `data_df` expect_error( - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_end(columns = c(mpg, cyls, disp))) }) diff --git a/tests/testthat/test-conditional_fmt.R b/tests/testthat/test-conditional_fmt.R index 01c6db158..5d37a7122 100644 --- a/tests/testthat/test-conditional_fmt.R +++ b/tests/testthat/test-conditional_fmt.R @@ -14,7 +14,7 @@ data_tbl <- # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset -tab <- gt(data = data_tbl) +tab <- gt(data_tbl) # Create an input data frame with dates, times, and date-times (all # as character) @@ -28,7 +28,7 @@ time_tbl <- # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset -tab_time <- gt(data = time_tbl) +tab_time <- gt(time_tbl) test_that("the `fmt_number()` function works with conditional `rows`", { diff --git a/tests/testthat/test-fmt_bytes.R b/tests/testthat/test-fmt_bytes.R index 96d60faa7..ccab7334a 100644 --- a/tests/testthat/test-fmt_bytes.R +++ b/tests/testthat/test-fmt_bytes.R @@ -31,7 +31,7 @@ test_that("the `fmt_bytes()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) @@ -343,7 +343,7 @@ test_that("the `fmt_bytes()` function format to specified significant figures", # Create a `gt_tbl` object with `gt()` and the # `numbers_tbl` dataset - tab <- gt(data = numbers_tbl) + tab <- gt(numbers_tbl) # Format the `num` column to 5 significant figures expect_equal( diff --git a/tests/testthat/test-fmt_currency.R b/tests/testthat/test-fmt_currency.R index 70602006b..250a902ae 100644 --- a/tests/testthat/test-fmt_currency.R +++ b/tests/testthat/test-fmt_currency.R @@ -17,22 +17,11 @@ test_that("the `fmt_currency()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms") - # ) - # ) - # Extract vectors from the table object for comparison # to the original dataset char_1 <- (tab %>% dt_data_get())[["char_1"]] @@ -283,7 +272,7 @@ test_that("the `fmt_currency()` function can scale/suffix larger numbers", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Format the `num` column to 2 decimal places, have the # `suffixing` option set to TRUE (default labels, all @@ -400,7 +389,7 @@ test_that("the `fmt_currency()` function can scale/suffix larger numbers", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl_2` dataset - tab_2 <- gt(data = data_tbl_2) + tab_2 <- gt(data_tbl_2) # # Adjust the `decimals` value to verify that @@ -517,7 +506,7 @@ test_that("the `currency()` helper function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Format the `num_1` column using the `currency()` helper function; # extract `output_df` in the HTML context and compare to expected values diff --git a/tests/testthat/test-fmt_date_time.R b/tests/testthat/test-fmt_date_time.R index 5b6cd01ab..5920da385 100644 --- a/tests/testthat/test-fmt_date_time.R +++ b/tests/testthat/test-fmt_date_time.R @@ -10,20 +10,11 @@ test_that("the `fmt_date()` function works correctly", { # Create a `tab` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms"))) - # Extract a vector from the table object for comparison # to the original dataset date <- (tab %>% dt_data_get())[["date"]] @@ -139,9 +130,8 @@ test_that("the `fmt_date()` function works correctly", { dplyr::tibble(date = as.Date(c( "2017-10-15", "2013-02-22", "2014-09-22", "2018-01-10"))) - # Create a `tab` object with `gt()` and the - # `data_tbl` dataset - tab <- gt(data = data_tbl) + # Create a `tab` object with `gt()` and the `data_tbl` dataset + tab <- gt(data_tbl) # # Format `date` in various date formats and verify the output @@ -250,20 +240,11 @@ test_that("the `fmt_time()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms"))) - # Extract a vector from the table object for comparison # to the original dataset time <- (tab %>% dt_data_get())[["time"]] @@ -325,20 +306,11 @@ test_that("the `fmt_datetime()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms"))) - # Extract a vector from the table object for comparison # to the original dataset datetime <- (tab %>% dt_data_get())[["datetime"]] diff --git a/tests/testthat/test-fmt_missing.R b/tests/testthat/test-fmt_missing.R index 1bc073adc..30952370b 100644 --- a/tests/testthat/test-fmt_missing.R +++ b/tests/testthat/test-fmt_missing.R @@ -12,20 +12,11 @@ test_that("the `fmt_missing()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms"))) - # Extract vectors from the table object for comparison # to the original dataset num_1 <- (tab %>% dt_data_get())[["num_1"]] diff --git a/tests/testthat/test-fmt_number.R b/tests/testthat/test-fmt_number.R index aecfc9879..1d020d96c 100644 --- a/tests/testthat/test-fmt_number.R +++ b/tests/testthat/test-fmt_number.R @@ -15,7 +15,7 @@ test_that("the `fmt_number()` function works correctly in the HTML context", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) @@ -289,7 +289,7 @@ test_that("the `fmt_number()` function can scale/suffix larger numbers", { ) # Create a `gt_tbl` object with `gt()` and the `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Format the `num` column to 2 decimal places, have the `suffixing` option # set to TRUE (default labels, all 4 ranges used) @@ -407,9 +407,8 @@ test_that("the `fmt_number()` function can scale/suffix larger numbers", { # numeric column and with one row data_tbl_2 <- data.frame(num = 999.9999) - # Create a `gt_tbl` object with `gt()` and the - # `data_tbl_2` dataset - tab_2 <- gt(data = data_tbl_2) + # Create a `gt_tbl` object with `gt()` and the `data_tbl_2` dataset + tab_2 <- gt(data_tbl_2) # # Adjust the `decimals` value to verify that @@ -493,7 +492,7 @@ test_that("the `fmt_number()` function format to specified significant figures", numbers_tbl <- dplyr::tibble(num = numbers) # Create a `gt_tbl` object with `gt()` and the `numbers_tbl` dataset - tab <- gt(data = numbers_tbl) + tab <- gt(numbers_tbl) # Format the `num` column to 5 significant figures expect_equal( @@ -590,9 +589,8 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio # Create a single-column tibble with these values in `num` numbers_tbl <- dplyr::tibble(num = numbers) - # Create a `gt_tbl` object with `gt()` and the - # `numbers_tbl` dataset - tab <- gt(data = numbers_tbl) + # Create a `gt_tbl` object with `gt()` and the `numbers_tbl` dataset + tab <- gt(numbers_tbl) # Format the `num` column using `fmt_number()` with default options expect_equal( @@ -731,7 +729,7 @@ test_that("`fmt_number()` with `suffixing = TRUE` works with small numbers", { ) # Create a `gt_tbl` object with `gt()` and the `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Format the `num` column to 2 decimal places, have the `suffixing` option # set to TRUE; we shouldn't expect to see any suffixes diff --git a/tests/testthat/test-fmt_passthrough.R b/tests/testthat/test-fmt_passthrough.R index abdeaf648..1eed4c696 100644 --- a/tests/testthat/test-fmt_passthrough.R +++ b/tests/testthat/test-fmt_passthrough.R @@ -16,20 +16,11 @@ test_that("the `fmt_passthrough()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c("names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms"))) - # Extract vectors from the table object for comparison # to the original dataset char_1 <- (tab %>% dt_data_get())[["char_1"]] diff --git a/tests/testthat/test-fmt_percent.R b/tests/testthat/test-fmt_percent.R index d6181552b..d6454bcbc 100644 --- a/tests/testthat/test-fmt_percent.R +++ b/tests/testthat/test-fmt_percent.R @@ -13,9 +13,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { stringsAsFactors = FALSE ) - # Create a `gt_tbl` object with `gt()` and the - # `data_tbl` dataset - tab <- gt(data = data_tbl) + # Create a `gt_tbl` object with `gt()` and the `data_tbl` dataset + tab <- gt(data_tbl) # Expect an error when attempting to format a column # that does not exist diff --git a/tests/testthat/test-fmt_scientific.R b/tests/testthat/test-fmt_scientific.R index 0d89e7303..60f4e652a 100644 --- a/tests/testthat/test-fmt_scientific.R +++ b/tests/testthat/test-fmt_scientific.R @@ -17,24 +17,11 @@ test_that("the `fmt_scientific()` function works correctly", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Expect that the object has the correct classes expect_is(tab, c("gt_tbl", "data.frame")) - # # Expect certain named attributes - # expect_true( - # all( - # names(attributes(tab)) %in% - # c( - # "names", "class", "row.names", - # "boxh_df", "stub_df", "footnotes_df", "styles_df", - # "rows_df", "cols_df", "col_labels", "grp_labels", - # "arrange_groups", "data_df", "opts_df", "formats", "transforms" - # ) - # ) - # ) - # Extract vectors from the table object for comparison # to the original dataset char_1 <- (tab %>% dt_data_get())[["char_1"]] @@ -340,7 +327,7 @@ test_that("`fmt_scientific()` can handle extremely large and small values", { # Create a `gt_tbl` object with `gt()` and the # `data_tbl` dataset - tab <- gt(data = data_tbl) + tab <- gt(data_tbl) # Format the `num` column to 5 decimal places, use all # other defaults; extract values in the default context diff --git a/tests/testthat/test-l_cols_align.R b/tests/testthat/test-l_cols_align.R index b401a361b..24ac15ce6 100644 --- a/tests/testthat/test-l_cols_align.R +++ b/tests/testthat/test-l_cols_align.R @@ -14,7 +14,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns are aligned left tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = c(mpg, cyl, drat)) %>% as_latex() %>% as.character() @@ -25,7 +25,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_latex` object with `gt()`; columns `1` (`mpg`), # `2` (`cyl`), and `3` (`disp`) are aligned right tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = 1:3) %>% as_latex() %>% as.character() @@ -36,7 +36,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_latex` object with `gt()`; align all # columns to the left tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left") %>% as_latex() %>% as.character() @@ -47,7 +47,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_latex` object with `gt()`; align all # columns (using `columns = everything()`) to the left tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_align(align = "left", columns = everything()) %>% as_latex() %>% as.character() @@ -58,7 +58,7 @@ test_that("the `cols_align()` function works correctly", { # Create a `tbl_latex` object with the `sp500` data # frame and `auto`-align all columns tbl_latex <- - gt(data = sp500) %>% + gt(sp500) %>% cols_align(align = "auto") %>% as_latex() %>% as.character() diff --git a/tests/testthat/test-l_cols_move.R b/tests/testthat/test-l_cols_move.R index d62c8aa01..6c78a3171 100644 --- a/tests/testthat/test-l_cols_move.R +++ b/tests/testthat/test-l_cols_move.R @@ -8,7 +8,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `drat` tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = drat) # Expect a characteristic pattern @@ -22,7 +22,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `drat` using vectors tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c("mpg", "cyl", "disp"), after = c("drat")) # Expect a characteristic pattern @@ -36,7 +36,7 @@ test_that("the `cols_move()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `mpg`, # `cyl`, and `drat` columns placed after `carb` (the end of the series) tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move(columns = c(mpg, cyl, disp), after = carb) # Expect a characteristic pattern @@ -53,7 +53,7 @@ test_that("the `cols_move_to_start()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `gear`, # and `carb` columns placed at the start tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_start(columns = c(gear, carb)) # Expect a characteristic pattern @@ -67,7 +67,7 @@ test_that("the `cols_move_to_start()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `gear`, # and `carb` columns placed at the start using vectors tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_start(columns = c("gear", "carb")) # Expect a characteristic pattern @@ -84,7 +84,7 @@ test_that("the `cols_move_to_end()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `gear`, # and `carb` columns placed at the end tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_end(columns = c(gear, carb)) # Expect a characteristic pattern @@ -98,7 +98,7 @@ test_that("the `cols_move_to_end()` function works correctly", { # Create a `tbl_latex` object with `gt()`; the `gear`, # and `carb` columns placed at the end using vectors tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% cols_move_to_end(columns = c("gear", "carb")) # Expect a characteristic pattern diff --git a/tests/testthat/test-l_conditional_fmt.R b/tests/testthat/test-l_conditional_fmt.R index 89f56ecbe..3d02db0fb 100644 --- a/tests/testthat/test-l_conditional_fmt.R +++ b/tests/testthat/test-l_conditional_fmt.R @@ -13,9 +13,8 @@ data_tbl <- stringsAsFactors = FALSE ) -# Create a `tbl_latex` object with `gt()` and the -# `data_tbl` dataset -tbl_latex <- gt(data = data_tbl) +# Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset +tbl_latex <- gt(data_tbl) # Create an input data frame with dates, times, and date-times (all # as character) @@ -28,9 +27,8 @@ time_tbl <- stringsAsFactors = FALSE ) -# Create a `tbl_latex_time` object with `gt()` and the -# `data_tbl` dataset -tbl_latex_time <- gt(data = time_tbl) +# Create a `tbl_latex_time` object with `gt()` and the `data_tbl` dataset +tbl_latex_time <- gt(time_tbl) test_that("the `fmt_number()` function works with conditional `rows`", { diff --git a/tests/testthat/test-l_fmt_currency.R b/tests/testthat/test-l_fmt_currency.R index 32f0994fb..30d88b4ee 100644 --- a/tests/testthat/test-l_fmt_currency.R +++ b/tests/testthat/test-l_fmt_currency.R @@ -17,7 +17,7 @@ test_that("the `fmt_currency()` function works correctly", { # Create a `tbl_latex` object with `gt()` and the # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + tbl_latex <- gt(data_tbl) # Format the `num_1` column as USD, use all other defaults; # extract `output_df` and compare to expected values diff --git a/tests/testthat/test-l_fmt_date_time.R b/tests/testthat/test-l_fmt_date_time.R index 19b6c11ec..22f2bb081 100644 --- a/tests/testthat/test-l_fmt_date_time.R +++ b/tests/testthat/test-l_fmt_date_time.R @@ -8,9 +8,8 @@ test_that("the `fmt_date()` function works correctly", { dplyr::tibble(date = c( "2017-10-15", "2013-02-22", "2014-09-22", "2018-01-10")) - # Create a `tbl_latex` object with `gt()` and the - # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + # Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset + tbl_latex <- gt(data_tbl) # # Format `date` in various date formats and verify the output @@ -112,9 +111,8 @@ test_that("the `fmt_date()` function works correctly", { dplyr::tibble(date = as.Date(c( "2017-10-15", "2013-02-22", "2014-09-22", "2018-01-10"))) - # Create a `tbl_latex` object with `gt()` and the - # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + # Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset + tbl_latex <- gt(data_tbl) # # Format `date` in various date formats and verify the output @@ -220,9 +218,8 @@ test_that("the `fmt_time()` function works correctly", { dplyr::tibble(time = c( "12:35:23", "15:01:34", "09:45:23", "01:32:00")) - # Create a `tbl_latex` object with `gt()` and the - # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + # Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset + tbl_latex <- gt(data_tbl) # # Format `time` in various date formats and verify the output @@ -270,9 +267,8 @@ test_that("the `fmt_datetime()` function works correctly", { "2017-08-05 09:45:23", "2017-10-23 01:32:00")) - # Create a `tbl_latex` object with `gt()` and the - # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + # Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset + tbl_latex <- gt(data_tbl) # # Format `time` in various date formats and verify the output diff --git a/tests/testthat/test-l_fmt_missing.R b/tests/testthat/test-l_fmt_missing.R index 957c59837..7725f8960 100644 --- a/tests/testthat/test-l_fmt_missing.R +++ b/tests/testthat/test-l_fmt_missing.R @@ -9,9 +9,8 @@ test_that("the `fmt_missing()` function works correctly", { num_2 = c(34, 74, 23, 93, 35, 76, 57), stringsAsFactors = FALSE) - # Create a `tbl_latex` object with `gt()` and the - # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + # Create a `tbl_latex` object with `gt()` and the `data_tbl` dataset + tbl_latex <- gt(data_tbl) # # Use `fmt_missing()` with various options diff --git a/tests/testthat/test-l_fmt_number.R b/tests/testthat/test-l_fmt_number.R index 807048673..d6422e2af 100644 --- a/tests/testthat/test-l_fmt_number.R +++ b/tests/testthat/test-l_fmt_number.R @@ -15,7 +15,7 @@ test_that("the `fmt_number()` function works correctly in the LaTeX context", { # Create a `tbl_latex` object with `gt()` and the # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + tbl_latex <- gt(data_tbl) # Format the `num_1` column to 2 decimal places, use all other defaults expect_equal( diff --git a/tests/testthat/test-l_fmt_passthrough.R b/tests/testthat/test-l_fmt_passthrough.R index 18aae9378..a8c062a32 100644 --- a/tests/testthat/test-l_fmt_passthrough.R +++ b/tests/testthat/test-l_fmt_passthrough.R @@ -16,7 +16,7 @@ test_that("the `fmt_passthrough()` function works correctly", { # Create a `tbl_latex` object with `gt()` and the # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + tbl_latex <- gt(data_tbl) # # Format `fmt_passthrough()` with various options diff --git a/tests/testthat/test-l_fmt_percent.R b/tests/testthat/test-l_fmt_percent.R index 23258d698..d4bd33c7b 100644 --- a/tests/testthat/test-l_fmt_percent.R +++ b/tests/testthat/test-l_fmt_percent.R @@ -15,7 +15,7 @@ test_that("the `fmt_percent()` function works correctly in the LaTeX context", { # Create a `tbl_latex` object with `gt()` and the # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + tbl_latex <- gt(data_tbl) # Format the `num_1` column to 2 decimal places, use all # other defaults; extract `output_df` and compare to expected values diff --git a/tests/testthat/test-l_fmt_scientific.R b/tests/testthat/test-l_fmt_scientific.R index de8b210c9..b2b1ba573 100644 --- a/tests/testthat/test-l_fmt_scientific.R +++ b/tests/testthat/test-l_fmt_scientific.R @@ -17,7 +17,7 @@ test_that("the `fmt_scientific()` function works correctly", { # Create a `tbl_latex` object with `gt()` and the # `data_tbl` dataset - tbl_latex <- gt(data = data_tbl) + tbl_latex <- gt(data_tbl) # Format the `num_1` column to 2 decimal places, use all # other defaults; extract `output_df` in the HTML context diff --git a/tests/testthat/test-l_table_parts.R b/tests/testthat/test-l_table_parts.R index 1d08b551e..e30c08d68 100644 --- a/tests/testthat/test-l_table_parts.R +++ b/tests/testthat/test-l_table_parts.R @@ -5,10 +5,9 @@ mtcars_short <- mtcars[1:5, ] test_that("a gt table contains the expected heading components", { - # Create a `tbl_latex` object with `gt()`; this table - # contains a title + # Create a `tbl_latex` object with `gt()`; this table contains a title tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% tab_header(title = "test title") # Expect a characteristic pattern @@ -22,7 +21,7 @@ test_that("a gt table contains the expected heading components", { # Create a `tbl_latex` object with `gt()`; this table # contains a title and a subtitle tbl_latex <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% tab_header(title = "test title", subtitle = "test subtitle") # Expect a characteristic pattern @@ -42,7 +41,7 @@ test_that("a gt table contains the expected stubhead label", { # Create a `tbl_latex` object with `gt()`; this table # contains a stub and a stubhead caption tbl_latex <- - gt(data = mtcars_short, rownames_to_stub = TRUE) %>% + gt(mtcars_short, rownames_to_stub = TRUE) %>% tab_stubhead(label = "the mtcars") # Expect a characteristic pattern @@ -61,7 +60,7 @@ test_that("a gt table contains the expected column spanner labels", { # contains the spanner heading `perimeter` over the # `peri` and `shape` column labels tbl_latex <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c("peri", "shape") @@ -83,7 +82,7 @@ test_that("a gt table contains the expected column spanner labels", { # `peri` and `shape` column labels (this time, using # `c()` to define the columns) tbl_latex <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c(peri, shape) @@ -103,7 +102,7 @@ test_that("a gt table contains the expected column spanner labels", { # Expect an error when using column labels # that don't exist expect_error( - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c(peris, shapes) diff --git a/tests/testthat/test-r_table_parts.R b/tests/testthat/test-r_table_parts.R index fbc176526..86abccc59 100644 --- a/tests/testthat/test-r_table_parts.R +++ b/tests/testthat/test-r_table_parts.R @@ -6,7 +6,7 @@ test_that("a gt table contains the expected column spanner labels", { # contains the spanner heading `perimeter` over the # `peri` and `shape` column labels tbl_rtf <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c("peri", "shape") diff --git a/tests/testthat/test-table_parts.R b/tests/testthat/test-table_parts.R index bdcd7ba2b..341f3f947 100644 --- a/tests/testthat/test-table_parts.R +++ b/tests/testthat/test-table_parts.R @@ -42,7 +42,7 @@ test_that("a gt table contains the expected heading components", { # Create a `tbl_html` object with `gt()`; this table # contains a title tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% tab_header(title = "test heading") %>% render_as_html() %>% xml2::read_html() @@ -67,7 +67,7 @@ test_that("a gt table contains the expected heading components", { # Create a `gt_tbl` object with `gt()`; this table # contains a title and a subtitle tbl_html <- - gt(data = mtcars_short) %>% + gt(mtcars_short) %>% tab_header( title = "test title", subtitle = "test subtitle") %>% @@ -93,7 +93,7 @@ test_that("a gt table contains the expected stubhead label", { # Create a `tbl_html` object with `gt()`; this table # contains a stub and a stubhead label tbl_html <- - gt(data = mtcars_short, rownames_to_stub = TRUE) %>% + gt(mtcars_short, rownames_to_stub = TRUE) %>% tab_stubhead(label = "the mtcars") %>% render_as_html() %>% xml2::read_html() @@ -114,7 +114,7 @@ test_that("a gt table contains the expected spanner column labels", { # contains the spanner heading `perimeter` over the # `peri` and `shape` column labels tbl_html <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c("peri", "shape")) %>% @@ -133,7 +133,7 @@ test_that("a gt table contains the expected spanner column labels", { # `peri` and `shape` column labels (this time, using # `c()` to define the columns) tbl_html <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c(peri, shape)) %>% @@ -151,7 +151,7 @@ test_that("a gt table contains the expected spanner column labels", { # contains the spanner heading `perimeter` that is formatted # with Markdown via `md()` tbl_html <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = md("*perimeter*"), columns = c("peri", "shape")) %>% @@ -166,7 +166,7 @@ test_that("a gt table contains the expected spanner column labels", { # contains the spanner heading `perimeter` that is formatted # with HTML via `html()` tbl_html <- - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = html("perimeter"), columns = c("peri", "shape")) %>% @@ -180,7 +180,7 @@ test_that("a gt table contains the expected spanner column labels", { # Expect an error when using column labels # that don't exist expect_error( - gt(data = rock) %>% + gt(rock) %>% tab_spanner( label = "perimeter", columns = c(peris, shapes)) @@ -281,7 +281,7 @@ test_that("`tab_spanner()` exclusively uses IDs for arranging spanners", { test_that("`tab_spanner()` doesn't adversely affect column alignment", { tbl_html <- - gt(data = airquality) %>% + gt(airquality) %>% cols_move_to_start(columns = c(Month, Day)) %>% cols_label(Solar.R = html("Solar
Radiation")) %>% tab_spanner( diff --git a/vignettes/intro-creating-gt-tables.Rmd b/vignettes/intro-creating-gt-tables.Rmd index d2c5868f6..035d55c48 100644 --- a/vignettes/intro-creating-gt-tables.Rmd +++ b/vignettes/intro-creating-gt-tables.Rmd @@ -52,7 +52,7 @@ The main entry point into the **gt** API is the `gt()` function. If we pass `isl ```{r simple_gt_table} # Create a display table showing ten of # the largest islands in the world -gt_tbl <- gt(data = islands_tbl) +gt_tbl <- gt(islands_tbl) # Show the gt Table gt_tbl @@ -302,7 +302,7 @@ airquality_m <- # Create a display table using the `airquality` # dataset; arrange columns into groups gt_tbl <- - gt(data = airquality_m) %>% + gt(airquality_m) %>% tab_header( title = "New York Air Quality Measurements", subtitle = "Daily measurements in New York City (May 1-10, 1973)" From 3d1f6798ea46b3b607409475e553d75bbe52f737 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 25 May 2021 15:40:56 -0400 Subject: [PATCH 02/10] Change to `.data` for all `fmt_*()` fns --- R/format_data.R | 201 ++++++++++++++++++++++++++--------------- man/fmt.Rd | 5 +- man/fmt_bytes.Rd | 4 +- man/fmt_currency.Rd | 4 +- man/fmt_date.Rd | 4 +- man/fmt_datetime.Rd | 4 +- man/fmt_markdown.Rd | 4 +- man/fmt_missing.Rd | 4 +- man/fmt_number.Rd | 4 +- man/fmt_passthrough.Rd | 4 +- man/fmt_percent.Rd | 4 +- man/fmt_scientific.Rd | 4 +- man/fmt_time.Rd | 4 +- man/gt.Rd | 6 +- 14 files changed, 158 insertions(+), 98 deletions(-) diff --git a/R/format_data.R b/R/format_data.R index a6abc6baf..585a3deaf 100644 --- a/R/format_data.R +++ b/R/format_data.R @@ -24,7 +24,7 @@ #' formatting is possible by providing a conditional expression to the `rows` #' argument. See the Arguments section for more information on this. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' @param columns The columns to format. Can either be a series of column names #' provided in [c()], a vector of column indices, or a helper function #' focused on selections. The select helper functions are: [starts_with()], @@ -143,7 +143,7 @@ #' #' @import rlang #' @export -fmt_number <- function(data, +fmt_number <- function(.data, columns, rows = everything(), decimals = 2, @@ -160,7 +160,7 @@ fmt_number <- function(data, locale = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Use locale-based marks if a locale ID is provided sep_mark <- get_locale_sep_mark(locale, sep_mark, use_seps) @@ -175,9 +175,17 @@ fmt_number <- function(data, # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = c("numeric", "integer"))) { - stop("The `fmt_number()` function can only be used on `columns` with numeric data", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = c("numeric", "integer") + ) + ) { + stop( + "The `fmt_number()` function can only be used on `columns` with numeric data.", + call. = FALSE + ) } # Set the `formatC_format` option according to whether number @@ -192,10 +200,10 @@ fmt_number <- function(data, formatC_format <- "f" } - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = num_fmt_factory_multi( @@ -290,7 +298,7 @@ fmt_number <- function(data, #' #' @import rlang #' @export -fmt_scientific <- function(data, +fmt_scientific <- function(.data, columns, rows = everything(), decimals = 2, @@ -302,7 +310,7 @@ fmt_scientific <- function(data, locale = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Set default values suffixing <- FALSE @@ -321,15 +329,23 @@ fmt_scientific <- function(data, # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = c("numeric", "integer"))) { - stop("The `fmt_scientific()` function can only be used on `columns` with numeric data", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = c("numeric", "integer") + ) + ) { + stop( + "The `fmt_scientific()` function can only be used on `columns` with numeric data.", + call. = FALSE + ) } - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = num_fmt_factory_multi( @@ -428,7 +444,7 @@ fmt_symbol <- function(data, # Pass `data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = data, columns = {{ columns }}, rows = {{ rows }}, fns = num_fmt_factory_multi( @@ -561,7 +577,7 @@ fmt_symbol <- function(data, #' #' @import rlang #' @export -fmt_percent <- function(data, +fmt_percent <- function(.data, columns, rows = everything(), decimals = 2, @@ -578,13 +594,21 @@ fmt_percent <- function(data, locale = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = c("numeric", "integer"))) { - stop("The `fmt_percent()` function can only be used on `columns` with numeric data", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = c("numeric", "integer") + ) + ) { + stop( + "The `fmt_percent()` function can only be used on `columns` with numeric data.", + call. = FALSE + ) } if (scale_values) { @@ -593,8 +617,9 @@ fmt_percent <- function(data, scale_by <- 1.0 } + # Pass `.data`, `columns`, `rows`, and other options to `fmt_symbol()` fmt_symbol( - data = data, + data = .data, columns = {{ columns }}, rows = {{ rows }}, symbol = "%", @@ -723,7 +748,7 @@ fmt_percent <- function(data, #' #' @import rlang #' @export -fmt_currency <- function(data, +fmt_currency <- function(.data, columns, rows = everything(), currency = "USD", @@ -742,13 +767,21 @@ fmt_currency <- function(data, locale = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = c("numeric", "integer"))) { - stop("The `fmt_currency()` function can only be used on `columns` with numeric data", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = c("numeric", "integer") + ) + ) { + stop( + "The `fmt_currency()` function can only be used on `columns` with numeric data.", + call. = FALSE + ) } # Stop function if `currency` does not have a valid value @@ -762,8 +795,9 @@ fmt_currency <- function(data, use_subunits = use_subunits ) + # Pass `.data`, `columns`, `rows`, and other options to `fmt_symbol()` fmt_symbol( - data = data, + data = .data, columns = {{ columns }}, rows = {{ rows }}, symbol = currency, @@ -850,7 +884,7 @@ fmt_currency <- function(data, #' #' @import rlang #' @export -fmt_bytes <- function(data, +fmt_bytes <- function(.data, columns, rows = everything(), standard = c("decimal", "binary"), @@ -866,7 +900,7 @@ fmt_bytes <- function(data, locale = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) standard <- match.arg(standard) @@ -896,8 +930,10 @@ fmt_bytes <- function(data, c("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB") } + # Pass `.data`, `columns`, `rows`, and the formatting + # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = num_fmt_factory_multi( @@ -1019,28 +1055,36 @@ fmt_bytes <- function(data, #' #' @import rlang #' @export -fmt_date <- function(data, +fmt_date <- function(.data, columns, rows = everything(), date_style = 2) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Transform `date_style` to `date_format_str` date_format_str <- get_date_format(date_style = date_style) # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = c("Date", "character"))) { - stop("The `fmt_date()` function can only be used on `columns` with `character` or `Date` values", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = c("Date", "character") + ) + ) { + stop( + "The `fmt_date()` function can only be used on `columns` with `character` or `Date` values.", + call. = FALSE + ) } - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1150,28 +1194,35 @@ fmt_date <- function(data, #' #' @import rlang #' @export -fmt_time <- function(data, +fmt_time <- function(.data, columns, rows = everything(), time_style = 2) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Transform `time_style` to `time_format_str` time_format_str <- get_time_format(time_style = time_style) # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = "character")) { - stop("The `fmt_date()` function can only be used on `columns` with `character` values", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = "character") + ) { + stop( + "The `fmt_date()` function can only be used on `columns` with `character` values.", + call. = FALSE + ) } - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1270,14 +1321,14 @@ fmt_time <- function(data, #' #' @import rlang #' @export -fmt_datetime <- function(data, +fmt_datetime <- function(.data, columns, rows = everything(), date_style = 2, time_style = 2) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Transform `date_style` to `date_format` date_format_str <- get_date_format(date_style = date_style) @@ -1287,15 +1338,22 @@ fmt_datetime <- function(data, # Stop function if any columns have data that is incompatible # with this formatter - if (!column_classes_are_valid(data, {{ columns }}, valid_classes = "character")) { - stop("The `fmt_datetime()` function can only be used on `columns` with `character` values", - call. = FALSE) + if ( + !column_classes_are_valid( + data = .data, + columns = {{ columns }}, + valid_classes = "character" + )) { + stop( + "The `fmt_datetime()` function can only be used on `columns` with `character` values.", + call. = FALSE + ) } - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1411,17 +1469,17 @@ fmt_datetime <- function(data, #' #' @import rlang #' @export -fmt_markdown <- function(data, +fmt_markdown <- function(.data, columns, rows = everything()) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions as a function list to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1498,19 +1556,19 @@ fmt_markdown <- function(data, #' #' @import rlang #' @export -fmt_passthrough <- function(data, +fmt_passthrough <- function(.data, columns, rows = everything(), escape = TRUE, pattern = "{x}") { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions (as a function list) to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1632,18 +1690,18 @@ fmt_passthrough <- function(data, #' #' @import rlang #' @export -fmt_missing <- function(data, +fmt_missing <- function(.data, columns, rows = everything(), missing_text = "---") { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - # Pass `data`, `columns`, `rows`, and the formatting + # Pass `.data`, `columns`, `rows`, and the formatting # functions (as a function list) to `fmt()` fmt( - data = data, + .data = .data, columns = {{ columns }}, rows = {{ rows }}, fns = list( @@ -1697,6 +1755,7 @@ fmt_missing <- function(data, #' **gt**. Along with the `columns` and `rows` arguments that provide some #' precision in targeting data cells, the `fns` argument allows you to define #' one or more functions for manipulating the raw data. +#' #' If providing a single function to `fns`, the recommended format is in the #' form: `fns = function(x) ...`. This single function will format the targeted #' data cells the same way regardless of the output format (e.g., HTML, LaTeX, @@ -1746,17 +1805,17 @@ fmt_missing <- function(data, #' #' @import rlang #' @export -fmt <- function(data, +fmt <- function(.data, columns = everything(), rows = everything(), fns) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the `stub_df` data frame from `data` - stub_df <- dt_stub_df_get(data = data) - data_tbl <- dt_data_get(data = data) + stub_df <- dt_stub_df_get(data = .data) + data_tbl <- dt_data_get(data = .data) # # Resolution of columns and rows as character vectors @@ -1765,13 +1824,13 @@ fmt <- function(data, resolved_columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) resolved_rows_idx <- resolve_rows_i( expr = {{ rows }}, - data = data + data = .data ) # If a single function is supplied to `fns` then @@ -1789,5 +1848,5 @@ fmt <- function(data, rows = resolved_rows_idx ) - dt_formats_add(data = data, formats = formatter_list) + dt_formats_add(data = .data, formats = formatter_list) } diff --git a/man/fmt.Rd b/man/fmt.Rd index cf8ba5819..2c1208b52 100644 --- a/man/fmt.Rd +++ b/man/fmt.Rd @@ -4,10 +4,10 @@ \alias{fmt} \title{Set a column format with a formatter function} \usage{ -fmt(data, columns = everything(), rows = everything(), fns) +fmt(.data, columns = everything(), rows = everything(), fns) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function @@ -35,6 +35,7 @@ than any of the specialized \verb{fmt_*()} functions that are available in \strong{gt}. Along with the \code{columns} and \code{rows} arguments that provide some precision in targeting data cells, the \code{fns} argument allows you to define one or more functions for manipulating the raw data. + If providing a single function to \code{fns}, the recommended format is in the form: \code{fns = function(x) ...}. This single function will format the targeted data cells the same way regardless of the output format (e.g., HTML, LaTeX, diff --git a/man/fmt_bytes.Rd b/man/fmt_bytes.Rd index 37b3f2baa..63af39526 100644 --- a/man/fmt_bytes.Rd +++ b/man/fmt_bytes.Rd @@ -5,7 +5,7 @@ \title{Format values as bytes} \usage{ fmt_bytes( - data, + .data, columns, rows = everything(), standard = c("decimal", "binary"), @@ -22,7 +22,7 @@ fmt_bytes( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_currency.Rd b/man/fmt_currency.Rd index dd2bdbde6..25b94d421 100644 --- a/man/fmt_currency.Rd +++ b/man/fmt_currency.Rd @@ -5,7 +5,7 @@ \title{Format values as currencies} \usage{ fmt_currency( - data, + .data, columns, rows = everything(), currency = "USD", @@ -25,7 +25,7 @@ fmt_currency( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_date.Rd b/man/fmt_date.Rd index 6b8c01c13..11f5f7b09 100644 --- a/man/fmt_date.Rd +++ b/man/fmt_date.Rd @@ -4,10 +4,10 @@ \alias{fmt_date} \title{Format values as dates} \usage{ -fmt_date(data, columns, rows = everything(), date_style = 2) +fmt_date(.data, columns, rows = everything(), date_style = 2) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_datetime.Rd b/man/fmt_datetime.Rd index b76558719..b18ebc4b6 100644 --- a/man/fmt_datetime.Rd +++ b/man/fmt_datetime.Rd @@ -5,7 +5,7 @@ \title{Format values as date-times} \usage{ fmt_datetime( - data, + .data, columns, rows = everything(), date_style = 2, @@ -13,7 +13,7 @@ fmt_datetime( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_markdown.Rd b/man/fmt_markdown.Rd index 03e498b3b..076796838 100644 --- a/man/fmt_markdown.Rd +++ b/man/fmt_markdown.Rd @@ -4,10 +4,10 @@ \alias{fmt_markdown} \title{Format Markdown text} \usage{ -fmt_markdown(data, columns, rows = everything()) +fmt_markdown(.data, columns, rows = everything()) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_missing.Rd b/man/fmt_missing.Rd index 61720237e..9213076bb 100644 --- a/man/fmt_missing.Rd +++ b/man/fmt_missing.Rd @@ -4,10 +4,10 @@ \alias{fmt_missing} \title{Format missing values} \usage{ -fmt_missing(data, columns, rows = everything(), missing_text = "---") +fmt_missing(.data, columns, rows = everything(), missing_text = "---") } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_number.Rd b/man/fmt_number.Rd index 48fda0250..e19d5f5d4 100644 --- a/man/fmt_number.Rd +++ b/man/fmt_number.Rd @@ -5,7 +5,7 @@ \title{Format numeric values} \usage{ fmt_number( - data, + .data, columns, rows = everything(), decimals = 2, @@ -23,7 +23,7 @@ fmt_number( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_passthrough.Rd b/man/fmt_passthrough.Rd index 3dcead6d2..21678ea2a 100644 --- a/man/fmt_passthrough.Rd +++ b/man/fmt_passthrough.Rd @@ -5,7 +5,7 @@ \title{Format by simply passing data through} \usage{ fmt_passthrough( - data, + .data, columns, rows = everything(), escape = TRUE, @@ -13,7 +13,7 @@ fmt_passthrough( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_percent.Rd b/man/fmt_percent.Rd index 1e183b0c9..d379d36b0 100644 --- a/man/fmt_percent.Rd +++ b/man/fmt_percent.Rd @@ -5,7 +5,7 @@ \title{Format values as a percentage} \usage{ fmt_percent( - data, + .data, columns, rows = everything(), decimals = 2, @@ -23,7 +23,7 @@ fmt_percent( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_scientific.Rd b/man/fmt_scientific.Rd index 172970b5e..a8596dee9 100644 --- a/man/fmt_scientific.Rd +++ b/man/fmt_scientific.Rd @@ -5,7 +5,7 @@ \title{Format values to scientific notation} \usage{ fmt_scientific( - data, + .data, columns, rows = everything(), decimals = 2, @@ -18,7 +18,7 @@ fmt_scientific( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/fmt_time.Rd b/man/fmt_time.Rd index 379afbc53..9f066edf5 100644 --- a/man/fmt_time.Rd +++ b/man/fmt_time.Rd @@ -4,10 +4,10 @@ \alias{fmt_time} \title{Format values as times} \usage{ -fmt_time(data, columns, rows = everything(), time_style = 2) +fmt_time(.data, columns, rows = everything(), time_style = 2) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns to format. Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of column indices, or a helper function diff --git a/man/gt.Rd b/man/gt.Rd index 25d0dc019..68db10d4e 100644 --- a/man/gt.Rd +++ b/man/gt.Rd @@ -5,9 +5,9 @@ \title{Create a \strong{gt} table object} \usage{ gt( - data, + .data, rowname_col = "rowname", - groupname_col = dplyr::group_vars(data), + groupname_col = dplyr::group_vars(.data), caption = NULL, rownames_to_stub = FALSE, auto_align = TRUE, @@ -16,7 +16,7 @@ gt( ) } \arguments{ -\item{data}{A \code{data.frame} object or a tibble.} +\item{.data}{A \code{data.frame} object or a tibble.} \item{rowname_col}{The column name in the input \code{data} table to use as row captions to be placed in the display table stub. If the \code{rownames_to_stub} From e707b8049a4a13fdcb94b5ecf3a0ed558b24438b Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 25 May 2021 16:54:17 -0400 Subject: [PATCH 03/10] Make final naming changes --- R/export.R | 129 ++++++++++++++++---------------- R/modify_rows.R | 11 ++- R/opts.R | 127 +++++++++++++++++++++++--------- R/summary_rows.R | 52 ++++++++----- R/tab_create_modify.R | 134 ++++++++++++++++++---------------- man/as_latex.Rd | 4 +- man/as_raw_html.Rd | 4 +- man/as_rtf.Rd | 4 +- man/extract_summary.Rd | 4 +- man/grand_summary_rows.Rd | 4 +- man/gtsave.Rd | 4 +- man/opt_align_table_header.Rd | 4 +- man/opt_all_caps.Rd | 4 +- man/opt_css.Rd | 4 +- man/opt_footnote_marks.Rd | 4 +- man/opt_row_striping.Rd | 4 +- man/opt_table_font.Rd | 4 +- man/opt_table_lines.Rd | 4 +- man/opt_table_outline.Rd | 4 +- man/row_group_order.Rd | 4 +- man/summary_rows.Rd | 4 +- man/tab_footnote.Rd | 4 +- man/tab_header.Rd | 4 +- man/tab_options.Rd | 4 +- man/tab_row_group.Rd | 11 ++- man/tab_source_note.Rd | 4 +- man/tab_spanner.Rd | 4 +- man/tab_spanner_delim.Rd | 4 +- man/tab_stubhead.Rd | 4 +- man/tab_style.Rd | 4 +- 30 files changed, 326 insertions(+), 234 deletions(-) diff --git a/R/export.R b/R/export.R index 33ed533a4..86fa0ac9f 100644 --- a/R/export.R +++ b/R/export.R @@ -38,7 +38,7 @@ #' document. The LaTeX and RTF saving functions don't have any options to pass #' to `...`. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' @param filename The file name to create on disk. Ensure that an extension #' compatible with the output types is provided (`.html`, `.tex`, `.ltx`, #' `.rtf`). If a custom save function is provided then the file extension is @@ -97,13 +97,13 @@ #' 13-1 #' #' @export -gtsave <- function(data, +gtsave <- function(.data, filename, path = NULL, ...) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Get the lowercased file extension file_ext <- gtsave_file_ext(filename) @@ -128,21 +128,23 @@ gtsave <- function(data, # Use the appropriate save function based # on the filename extension - switch(file_ext, - "htm" = , - "html" = gt_save_html(data, filename, path, ...), - "ltx" = , # We don't verbally support using `ltx` - "rnw" = , - "tex" = gt_save_latex(data, filename, path, ...), - "rtf" = gt_save_rtf(data, filename, path, ...), - "png" = , - "pdf" = gt_save_webshot(data, filename, path, ...), - { - stop("The file extension used (`.", file_ext, "`) doesn't have an ", - "associated saving function. ", - ext_supported_text, - call. = FALSE) - } + switch( + file_ext, + "htm" = , + "html" = gt_save_html(data = .data, filename, path, ...), + "ltx" = , # We don't verbally support using `ltx` + "rnw" = , + "tex" = gt_save_latex(data = .data, filename, path, ...), + "rtf" = gt_save_rtf(data = .data, filename, path, ...), + "png" = , + "pdf" = gt_save_webshot(data = .data, filename, path, ...), + { + stop( + "The file extension used (`.", file_ext, "`) doesn't have an ", + "associated saving function. ", ext_supported_text, + call. = FALSE + ) + } ) } @@ -230,7 +232,7 @@ gt_save_latex <- function(data, filename <- gtsave_filename(path = path, filename = filename) - writeLines(text = as_latex(data = data), con = filename) + writeLines(text = as_latex(.data = data), con = filename) } #' Saving function for an RTF file @@ -288,7 +290,7 @@ gtsave_filename <- function(path, filename) { #' tags. This option is preferable when using the output HTML table in an #' emailing context. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' @param inline_css An option to supply styles to table elements as inlined CSS #' styles. This is useful when including the table HTML as part of an HTML #' email message body, since inlined styles are largely supported in email @@ -323,25 +325,27 @@ gtsave_filename <- function(path, filename) { #' 13-2 #' #' @export -as_raw_html <- function(data, +as_raw_html <- function(.data, inline_css = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) if (inline_css) { # Generation of the HTML table - html_table <- render_as_html(data = data) + html_table <- render_as_html(data = .data) # Create inline styles html_table <- - html_table %>% - inline_html_styles(css_tbl = get_css_tbl(data)) + inline_html_styles( + html = html_table, + css_tbl = get_css_tbl(data = .data) + ) } else { - html_table <- as.character(as.tags.gt_tbl(data)) + html_table <- as.character(as.tags.gt_tbl(.data)) } htmltools::HTML(html_table) @@ -356,7 +360,7 @@ as_raw_html <- function(data, #' `as.character()` on the created object will result in a single-element vector #' containing the LaTeX code. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' #' @examples #' # Use `gtcars` to create a gt table; @@ -388,13 +392,13 @@ as_raw_html <- function(data, #' 13-3 #' #' @export -as_latex <- function(data) { +as_latex <- function(.data) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Build all table data objects through a common pipeline - data <- data %>% build_data(context = "latex") + data <- build_data(data = .data, context = "latex") # Composition of LaTeX ---------------------------------------------------- @@ -423,10 +427,7 @@ as_latex <- function(data) { # `latex_dependency()` function to load latex packages # without requiring the user to do so if (requireNamespace("rmarkdown", quietly = TRUE)) { - - latex_packages <- - lapply(latex_packages(), rmarkdown::latex_dependency) - + latex_packages <- lapply(latex_packages(), rmarkdown::latex_dependency) } else { latex_packages <- NULL } @@ -452,7 +453,7 @@ as_latex <- function(data) { #' vector. This object can be used with `writeLines()` to generate a valid .rtf #' file that can be opened by RTF readers. #' -#' @param data A table object that is created using the `gt()` function. +#' @param .data A table object that is created using the `gt()` function. #' @param page_numbering An option to include page numbering in the RTF #' document. The page numbering text can either be in the document `"footer"` #' or `"header"`. By default, page numbering is not active (`"none"`). @@ -477,16 +478,16 @@ as_latex <- function(data) { #' 13-4 #' #' @export -as_rtf <- function(data, +as_rtf <- function(.data, page_numbering = c("none", "footer", "header")) { page_numbering <- match.arg(page_numbering) # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Build all table data objects through a common pipeline - data <- data %>% build_data(context = "rtf") + data <- build_data(data = .data, context = "rtf") # Composition of RTF ------------------------------------------------------ @@ -507,24 +508,25 @@ as_rtf <- function(data, # Compose the RTF table rtf_table <- - rtf_file( - document = { - rtf_table( - rows = c( - heading_component, - columns_component, - body_component, - footnotes_component, - source_notes_component + as_rtf_string( + rtf_file( + document = { + rtf_table( + rows = c( + heading_component, + columns_component, + body_component, + footnotes_component, + source_notes_component + ) ) - ) - }, - page_numbering = page_numbering - ) %>% - as_rtf_string() + }, + page_numbering = page_numbering + ) + ) if (isTRUE(getOption('knitr.in.progress'))) { - rtf_table <- rtf_table %>% knitr::raw_output() + rtf_table <- knitr::raw_output(rtf_table) } rtf_table @@ -539,7 +541,7 @@ as_rtf <- function(data, #' contain the `group_id` and `rowname` columns, whereby `rowname` contains #' descriptive stub labels for the summary rows. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' #' @return A list of data frames containing summary data. #' @@ -595,24 +597,27 @@ as_rtf <- function(data, #' 13-5 #' #' @export -extract_summary <- function(data) { +extract_summary <- function(.data) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Stop function if there are no # directives to create summary rows - if (!dt_summary_exists(data = data)) { - stop("There is no summary list to extract.\n", - "Use the `summary_rows()` function to generate summaries.", - call. = FALSE) + if (!dt_summary_exists(data = .data)) { + + stop( + "There is no summary list to extract.\n", + "* Use the `summary_rows()` function to generate summaries.", + call. = FALSE + ) } # Build the `data` using the standard # pipeline with the `html` context - built_data <- build_data(data = data, context = "html") + built_data <- build_data(data = .data, context = "html") # Extract the list of summary data frames # that contains tidy, unformatted data - dt_summary_df_data_get(data = built_data) %>% as.list() + as.list(dt_summary_df_data_get(data = built_data)) } diff --git a/R/modify_rows.R b/R/modify_rows.R index 933ff30c5..fb4bbd61b 100644 --- a/R/modify_rows.R +++ b/R/modify_rows.R @@ -42,11 +42,11 @@ #' 5-1 #' #' @export -row_group_order <- function(data, +row_group_order <- function(.data, groups) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Stop function if `groups` is not a `character` vector if (!inherits(groups, "character")) { @@ -58,7 +58,7 @@ row_group_order <- function(data, } # Get the current arrangement of the row groups - arrange_groups <- dt_row_groups_get(data = data) + arrange_groups <- dt_row_groups_get(data = .data) # Stop function if any value in `groups` doesn't match a group name if (any(!groups %in% arrange_groups)) { @@ -75,5 +75,8 @@ row_group_order <- function(data, groups <- c(unique(groups), base::setdiff(arrange_groups, unique(groups))) # Create and store a list of row groups in the intended ordering - dt_row_groups_set(data = data, row_groups = groups) + dt_row_groups_set( + data = .data, + row_groups = groups + ) } diff --git a/R/opts.R b/R/opts.R index 9bf2ff2c7..2c7ce1500 100644 --- a/R/opts.R +++ b/R/opts.R @@ -78,16 +78,16 @@ #' 9-1 #' #' @export -opt_footnote_marks <- function(data, +opt_footnote_marks <- function(.data, marks) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Validate input for `marks` validate_marks(marks) - tab_options(data, footnotes.marks = marks) + tab_options(.data = .data, footnotes.marks = marks) } #' Option to add or remove row striping @@ -143,13 +143,16 @@ opt_footnote_marks <- function(data, #' 9-2 #' #' @export -opt_row_striping <- function(data, +opt_row_striping <- function(.data, row_striping = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - tab_options(data, row.striping.include_table_body = row_striping) + tab_options( + .data = .data, + row.striping.include_table_body = row_striping + ) } #' Option to align the table header @@ -207,15 +210,18 @@ opt_row_striping <- function(data, #' 9-3 #' #' @export -opt_align_table_header <- function(data, +opt_align_table_header <- function(.data, align = c("left", "center", "right")) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) align <- match.arg(align) - tab_options(data, heading.align = align) + tab_options( + .data = .data, + heading.align = align + ) } #' Option to use all caps in select table locations @@ -280,17 +286,20 @@ opt_align_table_header <- function(data, #' 9-4 #' #' @export -opt_all_caps <- function(data, +opt_all_caps <- function(.data, all_caps = TRUE, locations = c("column_labels", "stub", "row_group")) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Ensure that all named locations are valid if (!all(locations %in% c("column_labels", "stub", "row_group"))) { - stop("The available locations are `column_labels`, `stub`, and `row_group`.", - call. = FALSE) + + stop( + "The available locations are `column_labels`, `stub`, and `row_group`.", + call. = FALSE + ) } # Create a regex pattern to obtain arg names for all specific `locations` @@ -317,7 +326,10 @@ opt_all_caps <- function(data, option_value_list <- create_default_option_value_list(options_vec) } - tab_options_multi(data, option_value_list) + tab_options_multi( + .data = .data, + options = option_value_list + ) } #' Option to set table lines to different extents @@ -376,11 +388,11 @@ opt_all_caps <- function(data, #' 9-5 #' #' @export -opt_table_lines <- function(data, +opt_table_lines <- function(.data, extent = c("all", "none", "default")) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) extent <- match.arg(extent) @@ -396,7 +408,10 @@ opt_table_lines <- function(data, option_value_list <- create_default_option_value_list(options_vec) } - tab_options_multi(data, option_value_list) + tab_options_multi( + .data = .data, + options = option_value_list + ) } #' Option to wrap an outline around the entire table @@ -463,13 +478,13 @@ opt_table_lines <- function(data, #' 9-6 #' #' @export -opt_table_outline <- function(data, +opt_table_outline <- function(.data, style = "solid", width = px(3), color = "#D3D3D3") { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) if (style == "none") { width <- NULL @@ -499,7 +514,11 @@ opt_table_outline <- function(data, ) option_value_list <- create_option_value_list(options_vec, values_vec) - tab_options_multi(data, option_value_list) + + tab_options_multi( + .data = .data, + options = option_value_list + ) } #' Option to define a custom font for the table @@ -597,35 +616,67 @@ opt_table_outline <- function(data, #' 9-7 #' #' @export -opt_table_font <- function(data, +opt_table_font <- function(.data, font, weight = NULL, style = NULL, add = TRUE) { - existing_fonts <- dt_options_get_value(data = data, option = "table_font_names") - existing_additional_css <- dt_options_get_value(data = data, option = "table_additional_css") + existing_fonts <- + dt_options_get_value( + data = .data, + option = "table_font_names" + ) + + existing_additional_css <- + dt_options_get_value( + data = .data, + option = "table_additional_css" + ) font <- normalize_font_input(font_input = font) additional_css <- c(font$import_stmt, existing_additional_css) - data <- tab_options(data = data, table.font.names = c(font$name, if (add) existing_fonts)) - data <- tab_options(data = data, table.additional_css = additional_css) + .data <- + tab_options( + .data = .data, + table.font.names = c(font$name, if (add) existing_fonts) + ) + + .data <- + tab_options( + .data = .data, + table.additional_css = additional_css + ) if (!is.null(weight)) { if (is.numeric(weight)) weight <- as.character(weight) - data <- tab_options(data = data, table.font.weight = weight) - data <- tab_options(data = data, column_labels.font.weight = weight) + .data <- + tab_options( + .data = .data, + table.font.weight = weight + ) + + .data <- + tab_options( + .data = .data, + column_labels.font.weight = weight + ) } if (!is.null(style)) { - data <- tab_options(data = data, table.font.style = style) + + .data <- + tab_options( + .data = .data, + table.font.style = style + ) } - data + .data } #' Option to add custom CSS for the table @@ -689,23 +740,29 @@ opt_table_font <- function(data, #' 9-8 #' #' @export -opt_css <- function(data, +opt_css <- function(.data, css, add = TRUE, allow_duplicates = FALSE) { existing_additional_css <- - dt_options_get_value(data = data, option = "table_additional_css") + dt_options_get_value( + data = .data, + option = "table_additional_css" + ) css <- paste(css, collapse = "\n") if (!add && !allow_duplicates && css %in% existing_additional_css) { - return(data) + return(.data) } additional_css <- c(existing_additional_css, css) - tab_options(data = data, table.additional_css = additional_css) + tab_options( + .data = .data, + table.additional_css = additional_css + ) } normalize_font_input <- function(font_input) { @@ -799,10 +856,10 @@ validate_tab_options_args <- function(tab_options_args) { } # Do multiple calls of `tab_options()` with an option-value list (`options`) -tab_options_multi <- function(data, options) { +tab_options_multi <- function(.data, options) { # Validate the names of the `options` validate_tab_options_args(names(options)) - do.call(tab_options, c(list(data = data), options)) + do.call(tab_options, c(list(.data = .data), options)) } diff --git a/R/summary_rows.R b/R/summary_rows.R index 4f31943fc..b6c20321a 100644 --- a/R/summary_rows.R +++ b/R/summary_rows.R @@ -11,7 +11,7 @@ #' [extract_summary()] function can be used with a `gt_tbl` object where summary #' rows were added via `summary_rows()`. #' -#' @param data A table object that is created using the [gt()] function. +#' @param .data A table object that is created using the [gt()] function. #' @param groups The groups to consider for generation of groupwise summary #' rows. By default this is set to `NULL`, which results in the formation of #' grand summary rows (a grand summary operates on all table data). Providing @@ -83,7 +83,7 @@ #' 6-1 #' #' @export -summary_rows <- function(data, +summary_rows <- function(.data, groups = NULL, columns = everything(), fns, @@ -92,7 +92,7 @@ summary_rows <- function(data, ...) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Collect all provided formatter options in a list formatter_options <- list(...) @@ -103,25 +103,29 @@ summary_rows <- function(data, # is used for groupwise summaries across all # groups if (is_false(groups)) { - return(data) + return(.data) } # Get the `stub_df` object from `data` - stub_df <- dt_stub_df_get(data = data) + stub_df <- dt_stub_df_get(data = .data) - stub_available <- dt_stub_df_exists(data = data) + stub_available <- dt_stub_df_exists(data = .data) # Resolve the column names - columns <- resolve_cols_c(expr = {{ columns }}, data = data) + columns <- + resolve_cols_c( + expr = {{ columns }}, + data = .data + ) # If there isn't a stub available, create an # 'empty' stub (populated with empty strings); # the stub is necessary for summary row labels if (!stub_available) { - data <- + .data <- dt_boxhead_add_var( - data = data, + data = .data, var = "rowname", type = "stub", column_label = list("rowname"), @@ -131,18 +135,24 @@ summary_rows <- function(data, add_where = "bottom" ) + nrow_data <- nrow(.data$`_data`) + # Add the `"rowname"` column into `_data` - data$`_data` <- - data$`_data` %>% - dplyr::mutate(rowname = rep("", nrow(data$`_data`))) %>% - dplyr::select(dplyr::everything(), rowname) + .data$`_data` <- + .data$`_data` %>% + dplyr::mutate(rowname = rep("", .env$nrow_data)) %>% + dplyr::select(dplyr::everything(), .data$rowname) # Place the `rowname` values into `stub_df$rowname`; these are # empty strings which will provide an empty stub for locations # adjacent to the body rows stub_df[["rowname"]] <- "" - data <- dt_stub_df_set(data = data, stub_df = stub_df) + .data <- + dt_stub_df_set( + data = .data, + stub_df = stub_df + ) } # Derive the summary labels @@ -170,9 +180,13 @@ summary_rows <- function(data, formatter_options = formatter_options ) - data <- dt_summary_add(data = data, summary = summary_list) + .data <- + dt_summary_add( + data = .data, + summary = summary_list + ) - data + .data } #' Add grand summary rows using aggregation functions @@ -231,7 +245,7 @@ summary_rows <- function(data, #' 6-2 #' #' @export -grand_summary_rows <- function(data, +grand_summary_rows <- function(.data, columns = everything(), fns, missing_text = "---", @@ -239,10 +253,10 @@ grand_summary_rows <- function(data, ...) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) summary_rows( - data, + .data = .data, groups = NULL, columns = {{ columns }}, fns = fns, diff --git a/R/tab_create_modify.R b/R/tab_create_modify.R index b546c7618..804330b0c 100644 --- a/R/tab_create_modify.R +++ b/R/tab_create_modify.R @@ -37,15 +37,15 @@ #' 2-1 #' #' @export -tab_header <- function(data, +tab_header <- function(.data, title, subtitle = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) dt_heading_title_subtitle( - data = data, + data = .data, title = title, subtitle = subtitle ) @@ -105,14 +105,14 @@ tab_header <- function(data, #' 2-2 #' #' @export -tab_spanner <- function(data, +tab_spanner <- function(.data, label, columns, id = label, gather = TRUE) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) checkmate::assert_character( label, len = 1, any.missing = FALSE, null.ok = FALSE @@ -126,22 +126,22 @@ tab_spanner <- function(data, column_names <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) # If `column_names` evaluates to an empty vector or is NULL, # return the data unchanged if (length(column_names) < 1) { - return(data) + return(.data) } # Check `id` against existing `id` values and stop if necessary - check_spanner_id_unique(data = data, spanner_id = id) + check_spanner_id_unique(data = .data, spanner_id = id) # Add the spanner to the `_spanners` table - data <- + .data <- dt_spanners_add( - data = data, + data = .data, vars = column_names, spanner_label = label, spanner_id = id, @@ -151,15 +151,15 @@ tab_spanner <- function(data, if (isTRUE(gather) && length(column_names) >= 1) { # Move columns into place - data <- - data %>% + .data <- cols_move( + .data = .data, columns = column_names, after = column_names[1] ) } - data + .data } #' Create column labels and spanners via delimited names @@ -219,25 +219,25 @@ tab_spanner <- function(data, #' 2-3 #' #' @export -tab_spanner_delim <- function(data, +tab_spanner_delim <- function(.data, delim, columns = everything(), gather = TRUE, split = c("last", "first")) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) split <- match.arg(split) # Get all of the columns in the dataset - all_cols <- dt_boxhead_get_vars(data = data) + all_cols <- dt_boxhead_get_vars(data = .data) # Get the columns supplied in `columns` as a character vector columns <- resolve_cols_c( expr = {{ columns }}, - data = data + data = .data ) if (!is.null(columns)) { @@ -247,7 +247,7 @@ tab_spanner_delim <- function(data, } if (length(colnames) == 0) { - return(data) + return(.data) } colnames_has_delim <- grepl(pattern = delim, x = colnames, fixed = TRUE) @@ -277,9 +277,9 @@ tab_spanner_delim <- function(data, for (label in names(spanner_var_list)) { - data <- + .data <- tab_spanner( - data = data, + .data = .data, label = label, columns = spanner_var_list[[label]], gather = gather @@ -295,16 +295,16 @@ tab_spanner_delim <- function(data, new_labels_i <- new_labels[i] var_i <- colnames_with_delim[i] - data <- + .data <- dt_boxhead_edit( - data = data, + data = .data, var = var_i, column_label = new_labels_i ) } } - data + .data } #' Add a row group to a **gt** table @@ -390,7 +390,7 @@ tab_spanner_delim <- function(data, #' #' @import rlang #' @export -tab_row_group <- function(data, +tab_row_group <- function(.data, label, rows, id = label, @@ -398,9 +398,9 @@ tab_row_group <- function(data, group = NULL) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - arrange_groups_vars <- dt_row_groups_get(data = data) + arrange_groups_vars <- dt_row_groups_get(data = .data) if (!missing(group)) { @@ -418,7 +418,11 @@ tab_row_group <- function(data, # Warn user about `others_label` deprecation if (!is.null(others_label)) { - data <- tab_options(data = data, row_group.default_label = others_label) + .data <- + tab_options( + .data = .data, + row_group.default_label = others_label + ) warning( "The `others_label` argument has been deprecated in gt 0.3.0:\n", @@ -427,41 +431,42 @@ tab_row_group <- function(data, ) if (missing(label) && missing(rows) && missing(id)) { - return(data) + return(.data) } } # Check `id` against existing `id` values and stop if necessary - check_row_group_id_unique(data = data, row_group_id = id) + check_row_group_id_unique(data = .data, row_group_id = id) # Capture the `rows` expression row_expr <- rlang::enquo(rows) # Get the `stub_df` data frame from `data` - stub_df <- dt_stub_df_get(data = data) - data_tbl <- dt_data_get(data = data) + stub_df <- dt_stub_df_get(data = .data) + data_tbl <- dt_data_get(data = .data) # Resolve the row numbers using the `resolve_vars` function resolved_rows_idx <- resolve_rows_i( expr = !!row_expr, - data = data + data = .data ) - stub_df <- dt_stub_df_get(data = data) + stub_df <- dt_stub_df_get(data = .data) # Place the `label` in the `groupname` column `stub_df` stub_df[resolved_rows_idx, "group_label"] <- list(list(label)) stub_df[resolved_rows_idx, "group_id"] <- as.character(id) - data <- dt_stub_df_set(data = data, stub_df = stub_df) + .data <- dt_stub_df_set(data = .data, stub_df = stub_df) # Set the `_row_groups` vector here with the group id; new groups will # be placed at the front, pushing down `NA` (the 'Others' group) arrange_groups_vars <- c(id, stats::na.omit(arrange_groups_vars)) arrange_groups_vars <- unique(arrange_groups_vars) arrange_groups_vars <- arrange_groups_vars[arrange_groups_vars %in% stub_df$group_id] - if (dt_stub_groupname_has_na(data = data)) { + + if (dt_stub_groupname_has_na(data = .data)) { arrange_groups_vars <- c(arrange_groups_vars, NA_character_) } @@ -469,13 +474,13 @@ tab_row_group <- function(data, arrange_groups_vars <- character(0) } - data <- + .data <- dt_row_groups_set( - data = data, + data = .data, row_groups = arrange_groups_vars ) - data + .data } #' Add label text to the stubhead @@ -514,13 +519,13 @@ tab_row_group <- function(data, #' 2-5 #' #' @export -tab_stubhead <- function(data, +tab_stubhead <- function(.data, label) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) - dt_stubhead_label(data = data, label = label) + dt_stubhead_label(data = .data, label = label) } #' Add a table footnote @@ -599,12 +604,12 @@ tab_stubhead <- function(data, #' 2-6 #' #' @export -tab_footnote <- function(data, +tab_footnote <- function(.data, footnote, locations) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Resolve into a list of locations locations <- as_locations(locations) @@ -612,15 +617,16 @@ tab_footnote <- function(data, # Resolve the locations of the targeted data cells and append # the footnotes for (loc in locations) { - data <- + + .data <- set_footnote( loc = loc, - data = data, + data = .data, footnote = process_text(footnote) ) } - data + .data } set_footnote <- function(loc, data, footnote) { @@ -879,14 +885,14 @@ set_footnote.cells_footnotes <- function(loc, data, footnote) { #' 2-7 #' #' @export -tab_source_note <- function(data, +tab_source_note <- function(.data, source_note) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) dt_source_notes_add( - data = data, + data = .data, source_note = source_note ) } @@ -1026,12 +1032,12 @@ tab_source_note <- function(data, #' functions for targeting the locations to be styled. #' #' @export -tab_style <- function(data, +tab_style <- function(.data, style, locations) { # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Intercept font styles that require registration if ("cell_text" %in% names(style)) { @@ -1043,15 +1049,15 @@ tab_style <- function(data, existing_additional_css <- dt_options_get_value( - data = data, + data = .data, option = "table_additional_css" ) additional_css <- c(font$import_stmt, existing_additional_css) - data <- + .data <- tab_options( - data = data, + .data = .data, table.additional_css = additional_css ) @@ -1074,15 +1080,15 @@ tab_style <- function(data, # the format directives for (loc in locations) { - data <- + .data <- set_style( loc = loc, - data = data, + data = .data, style = style ) } - data + .data } as_style <- function(style) { @@ -1636,7 +1642,7 @@ set_style.cells_source_notes <- function(loc, data, style) { #' 2-9 #' #' @export -tab_options <- function(data, +tab_options <- function(.data, container.width = NULL, container.height = NULL, container.overflow.x = NULL, @@ -1773,12 +1779,12 @@ tab_options <- function(data, # TODO: add helper functions to divide the options into those by parameter # Perform input object validation - stop_if_not_gt(data = data) + stop_if_not_gt(data = .data) # Extract the options table from `data` - opts_df <- dt_options_get(data = data) + opts_df <- dt_options_get(data = .data) - arg_names <- formals(tab_options) %>% names() %>% base::setdiff("data") + arg_names <- formals(tab_options) %>% names() %>% base::setdiff(".data") arg_vals <- mget(arg_names) arg_vals <- arg_vals[!vapply(arg_vals, FUN = is.null, FUN.VALUE = logical(1))] arg_vals <- arg_vals %>% set_super_options() @@ -1812,10 +1818,10 @@ tab_options <- function(data, dplyr::anti_join(new_df, by = "parameter") ) - # Write the modified options table back to `data` - data <- dt_options_set(data = data, options = opts_df) + # Write the modified options table back to `.data` + .data <- dt_options_set(data = .data, options = opts_df) - data + .data } preprocess_tab_option <- function(option, var_name, type) { diff --git a/man/as_latex.Rd b/man/as_latex.Rd index 97882e1f3..330038540 100644 --- a/man/as_latex.Rd +++ b/man/as_latex.Rd @@ -4,10 +4,10 @@ \alias{as_latex} \title{Output a gt object as LaTeX} \usage{ -as_latex(data) +as_latex(.data) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} } \description{ Get the LaTeX content from a \code{gt_tbl} object as a \code{knit_asis} object. This diff --git a/man/as_raw_html.Rd b/man/as_raw_html.Rd index f519728f0..3e1de77e4 100644 --- a/man/as_raw_html.Rd +++ b/man/as_raw_html.Rd @@ -4,10 +4,10 @@ \alias{as_raw_html} \title{Get the HTML content of a \strong{gt} table} \usage{ -as_raw_html(data, inline_css = TRUE) +as_raw_html(.data, inline_css = TRUE) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{inline_css}{An option to supply styles to table elements as inlined CSS styles. This is useful when including the table HTML as part of an HTML diff --git a/man/as_rtf.Rd b/man/as_rtf.Rd index 5cd77b670..741cb1fb9 100644 --- a/man/as_rtf.Rd +++ b/man/as_rtf.Rd @@ -4,10 +4,10 @@ \alias{as_rtf} \title{Output a \strong{gt} object as RTF} \usage{ -as_rtf(data, page_numbering = c("none", "footer", "header")) +as_rtf(.data, page_numbering = c("none", "footer", "header")) } \arguments{ -\item{data}{A table object that is created using the \code{gt()} function.} +\item{.data}{A table object that is created using the \code{gt()} function.} \item{page_numbering}{An option to include page numbering in the RTF document. The page numbering text can either be in the document \code{"footer"} diff --git a/man/extract_summary.Rd b/man/extract_summary.Rd index 875c098b7..b7862790c 100644 --- a/man/extract_summary.Rd +++ b/man/extract_summary.Rd @@ -4,10 +4,10 @@ \alias{extract_summary} \title{Extract a summary list from a \strong{gt} object} \usage{ -extract_summary(data) +extract_summary(.data) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} } \value{ A list of data frames containing summary data. diff --git a/man/grand_summary_rows.Rd b/man/grand_summary_rows.Rd index afb770761..5af94f995 100644 --- a/man/grand_summary_rows.Rd +++ b/man/grand_summary_rows.Rd @@ -5,7 +5,7 @@ \title{Add grand summary rows using aggregation functions} \usage{ grand_summary_rows( - data, + .data, columns = everything(), fns, missing_text = "---", @@ -14,7 +14,7 @@ grand_summary_rows( ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{columns}{The columns for which the summaries should be calculated.} diff --git a/man/gtsave.Rd b/man/gtsave.Rd index 3f89f54f2..fefd356bd 100644 --- a/man/gtsave.Rd +++ b/man/gtsave.Rd @@ -4,10 +4,10 @@ \alias{gtsave} \title{Save a \strong{gt} table as a file} \usage{ -gtsave(data, filename, path = NULL, ...) +gtsave(.data, filename, path = NULL, ...) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{filename}{The file name to create on disk. Ensure that an extension compatible with the output types is provided (\code{.html}, \code{.tex}, \code{.ltx}, diff --git a/man/opt_align_table_header.Rd b/man/opt_align_table_header.Rd index d3a1aa48e..dd97719ab 100644 --- a/man/opt_align_table_header.Rd +++ b/man/opt_align_table_header.Rd @@ -4,10 +4,10 @@ \alias{opt_align_table_header} \title{Option to align the table header} \usage{ -opt_align_table_header(data, align = c("left", "center", "right")) +opt_align_table_header(.data, align = c("left", "center", "right")) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{align}{The alignment of the title and subtitle elements in the table header. Options are \code{"left"} (the default), \code{"center"}, or \code{"right"}.} diff --git a/man/opt_all_caps.Rd b/man/opt_all_caps.Rd index 9de99bf53..6615a30d1 100644 --- a/man/opt_all_caps.Rd +++ b/man/opt_all_caps.Rd @@ -5,13 +5,13 @@ \title{Option to use all caps in select table locations} \usage{ opt_all_caps( - data, + .data, all_caps = TRUE, locations = c("column_labels", "stub", "row_group") ) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{all_caps}{A logical value to indicate whether the text transformation to all caps should be performed (\code{TRUE}, the default) or reset to default diff --git a/man/opt_css.Rd b/man/opt_css.Rd index 1ca2863f6..0f4713ad1 100644 --- a/man/opt_css.Rd +++ b/man/opt_css.Rd @@ -4,10 +4,10 @@ \alias{opt_css} \title{Option to add custom CSS for the table} \usage{ -opt_css(data, css, add = TRUE, allow_duplicates = FALSE) +opt_css(.data, css, add = TRUE, allow_duplicates = FALSE) } \arguments{ -\item{data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} +\item{.data}{A table object that is created using the \code{\link[=gt]{gt()}} function.} \item{css}{The CSS to include as part of the rendered table's \verb{