diff --git a/DESCRIPTION b/DESCRIPTION index 9c93c1f601..35459bb95b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -124,7 +124,6 @@ Collate: 'opts.R' 'print.R' 'reexports.R' - 'render_as_gtable.R' 'render_as_html.R' 'render_as_i_html.R' 'resolver.R' diff --git a/NAMESPACE b/NAMESPACE index fc6357b20e..897d11edcf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -53,6 +53,7 @@ S3method(to_output_location,default) S3method(to_output_location,output_relative) export("%>%") export(adjust_luminance) +export(as_gtable) export(as_latex) export(as_raw_html) export(as_rtf) diff --git a/R/export.R b/R/export.R index 56037eb627..ecdf6b0aea 100644 --- a/R/export.R +++ b/R/export.R @@ -1166,6 +1166,363 @@ as_word_tbl_body <- function( as.character(word_tbl) } + +#' Transform a **gt** table to a `gtable` object +#' +#' @description +#' +#' The `as_gtable()` function performs the transformation of a `gt_tbl` object +#' to a `gtable` object. +#' +#' @param data *The gt table data object* +#' +#' `obj:` // **required** +#' +#' This is the **gt** table object that is commonly created through use of the +#' [gt()] function. +#' +#' @param plot *Render through the graphics device?* +#' +#' `scalar` // *default:* `FALSE` +#' +#' The `plot` option determines whether the `gtable` object should be rendered +#' on the graphics device. +#' +#' @param text_grob +#' +#' `function` // *default:* `grid::textGrob` +#' +#' A `function` used to draw text. Defaults to `grid::textGrob()` but can be +#' swapped to `gridtext::richtext_grob()` to better render HTML content. +#' +#' @return A `gtable` object. +#' +#' @family table export functions +#' @section Function ID: +#' 13-6 +#' +#' @section Function Introduced: +#' *In Development* +#' +#' @export +as_gtable <- function(data, plot = FALSE, text_grob = grid::textGrob) { + + data <- build_data(data = data, context = "html") + data <- add_css_styles(data = data) + + caption_component <- create_caption_component_g(data = data) + heading_component <- create_heading_component_g(data = data) + columns_component <- create_columns_component_g(data = data) + body_component <- create_body_component_g(data = data) + source_notes_component <- create_source_notes_component_g(data = data) + footnotes_component <- create_footnotes_component_g(data = data) + + layout <- + combine_components( + caption = caption_component, + heading = heading_component, + columns = columns_component, + body = body_component, + source = source_notes_component, + footnotes = footnotes_component + ) + + layout$grobs <- + render_grobs( + layout = layout, + data = data, + text_grob = text_grob + ) + + gtable <- finalize_gtable(layout, data) + + if (isTRUE(plot)) { + plot(gtable) + } + + gtable +} + +combine_components <- function( + caption = NULL, + heading = NULL, + columns = NULL, + body = NULL, + source = NULL, + footnotes = NULL +) { + + vertical <- c("top", "bottom") + n <- n_caption <- max(caption$bottom %||% 0) + + if (!is.null(heading)) { + heading[vertical] <- heading[vertical] + n + n <- max(heading$bottom %||% n) + } + + if (!is.null(columns)) { + columns[vertical] <- columns[vertical] + n + n <- max(columns$bottom %||% n) + } + + body_start <- n + + if (!is.null(body)) { + body[vertical] <- body[vertical] + n + n <- max(body$bottom %||% n) + } + + body_end <- n + + if (!is.null(footnotes)) { + footnotes[vertical] <- footnotes[vertical] + n + n <- max(footnotes$bottom %||% n) + } + + if (!is.null(source)) { + source[vertical] <- source[vertical] + n + } + + n_cols <- max(body$right) + + # A table body typically renders top and bottom borders for the + # body part; we implement this as a large cell without a label + table_body <- + grid_layout( + left = 1, + right = n_cols, + label = "", + classes = list("gt_table_body"), + style = "background-color: transparent", + top = body_start + 1, + bottom = body_end, + name = "table_body" + ) + + # The table itself renders top and bottom borders for everything excluding + # the caption + table <- + grid_layout( + left = 1, + right = n_cols, + label = "", + classes = list("gt_table"), + style = "background-color: transparent", + top = n_caption + 1, + bottom = max(source$bottom %||% n), + name = "table" + ) + + vctrs::vec_c( + caption, heading, columns, body, + source, footnotes, table_body, table + ) +} + +render_grobs <- function( + layout, data, + text_grob = grid::textGrob, + cell_grob = grid::segmentsGrob +) { + + style <- grid_resolve_style(layout = layout, data = data) + + Map( + label = layout$label, + style = style, + f = render_grid_cell, + MoreArgs = list( + text_grob = text_grob, + cell_grob = cell_grob + ), + USE.NAMES = FALSE + ) +} + +finalize_gtable <- function(layout, data) { + + rlang::check_installed("gtable", "to render as a gtable.") + + widths <- grid_layout_widths(layout, data) + heights <- grid_layout_heights(layout) + + name <- layout$name + + name <- + stats::ave(name, name, FUN = function(nm) { + + if (length(nm) == 1) { + return(nm) + } + + paste0(nm, "_", seq_along(nm)) + }) + + gtable <- gtable::gtable(widths = widths, heights = heights) + gtable <- gtable::gtable_add_grob( + gtable, layout$grobs, name = name, clip = "off", + t = layout$top, l = layout$left, b = layout$bottom, r = layout$right + ) + gtable <- grid_align_gtable(gtable, data) + class(gtable) <- union("gt_gtable", class(gtable)) + gtable +} + +#' @export +plot.gt_gtable <- function(x, ...) { + grid::grid.newpage() + grid::grid.draw(x) +} + +grid_layout_heights <- function(layout) { + + heights <- vapply(layout$grobs, `[[`, numeric(1), "height") + + rows <- vctrs::vec_group_loc(layout[, c("top", "bottom")]) + rows$height <- vapply(rows$loc, function(i) max(heights[i]), numeric(1)) + + is_single <- rows$key$top == rows$key$bottom + singles <- rows[is_single, ] + spanner <- rows[!is_single, ] + + heights <- rep(0, max(layout$bottom)) + heights[singles$key$top] <- singles$height + spanner <- spanner[order(spanner$key$top, spanner$key$bottom), ] + + for (i in seq_len(nrow(spanner))) { + + top <- spanner$key$top[i] + bottom <- spanner$key$bottom[i] + single_size <- sum(heights[top:bottom]) + extra_height <- spanner$height[i] - single_size + + if (extra_height < 0) { + next + } + + extra_height <- extra_height / (bottom - top + 1) + heights[top:bottom] <- heights[top:bottom] + extra_height + } + + grid::unit(heights, .grid_unit) +} + +grid_align_gtable <- function(gtable, data) { + + left <- dt_options_get_value(data, "table_margin_left") + right <- dt_options_get_value(data, "table_margin_right") + + if (left == "auto") { + + left <- grid::unit(0.5, "null") + + } else if (grepl("\\%$", left)) { + + left <- as.numeric(gsub("\\%$", "", left)) / 100 + left <- grid::unit(left * 0.5, "null") + + } else { + + left <- grid::unit(parse_px_to_pt(left), "pt") + } + + if (right == "auto") { + + right <- grid::unit(0.5, "null") + + } else if (grepl("\\%$", right)) { + + right <- as.numeric(gsub("\\%$", "", right)) / 100 + right <- grid::unit(right * 0.5, "null") + + } else { + + right <- grid::unit(grid::unit(parse_px_to_pt(left), "pt")) + } + + gtable <- gtable::gtable_add_cols(gtable, left, pos = 0) + gtable <- gtable::gtable_add_cols(gtable, right, pos = -1) + gtable +} + +grid_layout_widths <- function(layout, data) { + + widths <- vapply(layout$grobs, `[[`, numeric(1), "width") + + columns <- vctrs::vec_group_loc(layout[, c("left", "right")]) + columns$width <- vapply(columns$loc, function(i) max(widths[i]), numeric(1)) + + is_single <- columns$key$left == columns$key$right + singles <- columns[is_single, ] + spanner <- columns[!is_single, ] + + widths <- rep(0, max(layout$right)) + widths[singles$key$left] <- singles$width + + # Enlarge columns if fixed column widths have been set + column_width <- unlist(dt_boxhead_get(data)$column_width) + fixed <- integer(0) + + if (any(nzchar(column_width)) && length(column_width) == length(widths)) { + + fixed <- which(nzchar(column_width)) + widths[fixed] <- pmax(parse_px_to_pt(column_width[fixed]), widths[fixed]) + } + + spanner <- spanner[order(spanner$key$left, spanner$key$right), ] + + for (i in seq_len(nrow(spanner))) { + + left <- spanner$key$left[i] + right <- spanner$key$right[i] + single_size <- sum(widths[left:right]) + extra_width <- spanner$width[i] - single_size + + if (extra_width < 0) { + next + } + extra_width <- extra_width / (right - left + 1) + widths[left:right] <- widths[left:right] + extra_width + } + + total_width <- dt_options_get_value(data, "table_width") + + if (grepl("px$", total_width)) { + + total_width <- parse_px_to_pt(total_width) + extra_width <- total_width - sum(widths) + + if (extra_width <= 0 || length(fixed) == length(widths)) { + return(grid::unit(widths, .grid_unit)) + } + + change <- setdiff(seq_along(widths), fixed) + widths[change] <- widths[change] + extra_width / (length(widths[change])) + + return(grid::unit(widths, .grid_unit)) + } + + if (grepl("\\%$", total_width)) { + + # Set the total width in npc units + total_width <- as.numeric(gsub("\\%$", "", total_width)) / 100 + change <- setdiff(seq_along(widths), fixed) + extra_width <- rep(0, length(widths)) + extra_width[change] <- total_width / length(change) + extra_width <- grid::unit(extra_width, "npc") + + # Subtract the size of fixed columns from the npc units + extra_width[change] <- extra_width[change] - + grid::unit(sum(widths[fixed]) / length(change), .grid_unit) + + # Take pairwise max between minimal size and relative size + widths <- grid::unit.pmax(grid::unit(widths, .grid_unit), extra_width) + return(widths) + } + + grid::unit(widths, .grid_unit) +} + #' Extract the table body from a **gt** object #' #' @description @@ -1246,7 +1603,7 @@ as_word_tbl_body <- function( #' #' @family table export functions #' @section Function ID: -#' 13-6 +#' 13-7 #' #' @section Function Introduced: #' `v0.10.0` (October 7, 2023) @@ -1396,7 +1753,7 @@ extract_body <- function( #' #' @family table export functions #' @section Function ID: -#' 13-7 +#' 13-8 #' #' @section Function Introduced: #' `v0.2.0.5` (March 31, 2020) @@ -1540,7 +1897,7 @@ extract_summary <- function(data) { #' #' @family table export functions #' @section Function ID: -#' 13-8 +#' 13-9 #' #' @section Function Introduced: #' `v0.8.0` (November 16, 2022) diff --git a/R/render_as_gtable.R b/R/render_as_gtable.R deleted file mode 100644 index c25f82a6a1..0000000000 --- a/R/render_as_gtable.R +++ /dev/null @@ -1,283 +0,0 @@ - -#' Transform a **gt** table object to a gtable -#' -#' Take a `gt_tbl` table object and transform it to a gtable. -#' -#' @param data A table object that is created using the `gt()` function. -#' @param plot A `logical(1)` whether the gtable should be rendered on the -#' graphics device. -#' @param text_grob A `function` used to draw text. Defaults to -#' `grid::textGrob()`, but can be swapped to `gridtext::richtext_grob()` to -#' better render html content. -#' -#' @return A `gtable` object -#' -#' @noRd -render_as_gtable <- function(data, plot = FALSE, text_grob = grid::textGrob) { - - data <- build_data(data = data, context = "html") - data <- add_css_styles(data = data) - - caption_component <- - create_caption_component_g(data = data) - heading_component <- - create_heading_component_g(data = data) - columns_component <- - create_columns_component_g(data = data) - body_component <- - create_body_component_g(data = data) - source_notes_component <- - create_source_notes_component_g(data = data) - footnotes_component <- - create_footnotes_component_g(data = data) - - layout <- - combine_components( - caption = caption_component, - heading = heading_component, - columns = columns_component, - body = body_component, - source = source_notes_component, - footnotes = footnotes_component - ) - - layout$grobs <- - render_grobs(layout = layout, data = data, text_grob = text_grob) - - gtable <- finalize_gtable(layout, data) - if (isTRUE(plot)) { - plot(gtable) - } - gtable -} - -combine_components <- function(caption = NULL, heading = NULL, columns = NULL, - body = NULL, source = NULL, footnotes = NULL) { - vertical <- c("top", "bottom") - n <- n_caption <- max(caption$bottom %||% 0) - - if (!is.null(heading)) { - heading[vertical] <- heading[vertical] + n - n <- max(heading$bottom %||% n) - } - - if (!is.null(columns)) { - columns[vertical] <- columns[vertical] + n - n <- max(columns$bottom %||% n) - } - - body_start <- n - if (!is.null(body)) { - body[vertical] <- body[vertical] + n - n <- max(body$bottom %||% n) - } - body_end <- n - - if (!is.null(footnotes)) { - footnotes[vertical] <- footnotes[vertical] + n - n <- max(footnotes$bottom %||% n) - } - - if (!is.null(source)) { - source[vertical] <- source[vertical] + n - } - - n_cols <- max(body$right) - # A table body typically renders top and bottom borders for the - # body part. We implement this a large cell without label - table_body <- grid_layout( - left = 1, right = n_cols, - label = "", - classes = list("gt_table_body"), - style = "background-color: transparent", - top = body_start + 1, bottom = body_end, - name = "table_body" - ) - - # The table itself renders top and bottom borders for everything excluding - # the caption - table <- grid_layout( - left = 1, right = n_cols, - label = "", - classes = list("gt_table"), - style = "background-color: transparent", - top = n_caption + 1, bottom = max(source$bottom %||% n), - name = "table" - ) - - vctrs::vec_c( - caption, heading, columns, body, source, footnotes, - table_body, table - ) -} - -render_grobs <- function( - layout, data, - text_grob = grid::textGrob, - cell_grob = grid::segmentsGrob -) { - style <- grid_resolve_style(layout = layout, data = data) - Map( - label = layout$label, - style = style, - f = render_grid_cell, - MoreArgs = list( - text_grob = text_grob, - cell_grob = cell_grob - ), - USE.NAMES = FALSE - ) -} - -finalize_gtable <- function(layout, data) { - check_installed("gtable", "to render as a gtable.") - - widths <- grid_layout_widths(layout, data) - heights <- grid_layout_heights(layout) - - name <- layout$name - name <- stats::ave(name, name, FUN = function(nm) { - if (length(nm) == 1) { - return(nm) - } - paste0(nm, "_", seq_along(nm)) - }) - - gtable <- gtable::gtable(widths = widths, heights = heights) - gtable <- gtable::gtable_add_grob( - gtable, layout$grobs, name = name, clip = "off", - t = layout$top, l = layout$left, b = layout$bottom, r = layout$right - ) - gtable <- grid_align_gtable(gtable, data) - class(gtable) <- union("gt_gtable", class(gtable)) - gtable -} - -#' @export -plot.gt_gtable <- function(x, ...) { - grid::grid.newpage() - grid::grid.draw(x) -} - -grid_layout_heights <- function(layout) { - - heights <- vapply(layout$grobs, `[[`, numeric(1), "height") - - rows <- vctrs::vec_group_loc(layout[, c("top", "bottom")]) - rows$height <- vapply(rows$loc, function(i) max(heights[i]), numeric(1)) - - is_single <- rows$key$top == rows$key$bottom - singles <- rows[is_single, ] - spanner <- rows[!is_single, ] - - heights <- rep(0, max(layout$bottom)) - heights[singles$key$top] <- singles$height - spanner <- spanner[order(spanner$key$top, spanner$key$bottom), ] - - for (i in seq_len(nrow(spanner))) { - top <- spanner$key$top[i] - bottom <- spanner$key$bottom[i] - single_size <- sum(heights[top:bottom]) - extra_height <- spanner$height[i] - single_size - if (extra_height < 0) { - next - } - extra_height <- extra_height / (bottom - top + 1) - heights[top:bottom] <- heights[top:bottom] + extra_height - } - grid::unit(heights, .grid_unit) -} - -grid_align_gtable <- function(gtable, data) { - - left <- dt_options_get_value(data, "table_margin_left") - right <- dt_options_get_value(data, "table_margin_right") - - if (left == "auto") { - left <- grid::unit(0.5, "null") - } else if (grepl("\\%$", left)) { - left <- as.numeric(gsub("\\%$", "", left)) / 100 - left <- grid::unit(left * 0.5, "null") - } else { - left <- grid::unit(parse_px_to_pt(left), "pt") - } - - if (right == "auto") { - right <- grid::unit(0.5, "null") - } else if (grepl("\\%$", right)) { - right <- as.numeric(gsub("\\%$", "", right)) / 100 - right <- grid::unit(right * 0.5, "null") - } else { - right <- grid::unit(grid::unit(parse_px_to_pt(left), "pt")) - } - - gtable <- gtable::gtable_add_cols(gtable, left, pos = 0) - gtable <- gtable::gtable_add_cols(gtable, right, pos = -1) - gtable -} - -grid_layout_widths <- function(layout, data) { - - widths <- vapply(layout$grobs, `[[`, numeric(1), "width") - - columns <- vctrs::vec_group_loc(layout[, c("left", "right")]) - columns$width <- vapply(columns$loc, function(i) max(widths[i]), numeric(1)) - - is_single <- columns$key$left == columns$key$right - singles <- columns[is_single, ] - spanner <- columns[!is_single, ] - - widths <- rep(0, max(layout$right)) - widths[singles$key$left] <- singles$width - - # Enlarge columns if fixed column widths have been set - column_width <- unlist(dt_boxhead_get(data)$column_width) - fixed <- integer(0) - if (any(nzchar(column_width)) && length(column_width) == length(widths)) { - fixed <- which(nzchar(column_width)) - widths[fixed] <- pmax(parse_px_to_pt(column_width[fixed]), widths[fixed]) - } - - spanner <- spanner[order(spanner$key$left, spanner$key$right), ] - - for (i in seq_len(nrow(spanner))) { - left <- spanner$key$left[i] - right <- spanner$key$right[i] - single_size <- sum(widths[left:right]) - extra_width <- spanner$width[i] - single_size - if (extra_width < 0) { - next - } - extra_width <- extra_width / (right - left + 1) - widths[left:right] <- widths[left:right] + extra_width - } - - total_width <- dt_options_get_value(data, "table_width") - if (grepl("px$", total_width)) { - total_width <- parse_px_to_pt(total_width) - extra_width <- total_width - sum(widths) - if (extra_width <= 0 || length(fixed) == length(widths)) { - return(grid::unit(widths, .grid_unit)) - } - change <- setdiff(seq_along(widths), fixed) - widths[change] <- widths[change] + extra_width / (length(widths[change])) - return(grid::unit(widths, .grid_unit)) - } - if (grepl("\\%$", total_width)) { - # Set the total width in npc units - total_width <- as.numeric(gsub("\\%$", "", total_width)) / 100 - change <- setdiff(seq_along(widths), fixed) - extra_width <- rep(0, length(widths)) - extra_width[change] <- total_width / length(change) - extra_width <- grid::unit(extra_width, "npc") - - # Subtract the size of fixed columns from the npc units - extra_width[change] <- extra_width[change] - - grid::unit(sum(widths[fixed]) / length(change), .grid_unit) - - # Take pairwise max between minimal size and relative size - widths <- grid::unit.pmax(grid::unit(widths, .grid_unit), extra_width) - return(widths) - } - return(grid::unit(widths, .grid_unit)) -} diff --git a/R/utils_render_grid.R b/R/utils_render_grid.R index fc59911654..cd2d0dd266 100644 --- a/R/utils_render_grid.R +++ b/R/utils_render_grid.R @@ -30,7 +30,7 @@ # A text label to display in the cell. Note that while the label can contain # html, it will not be rendered with markup unless the text grob function # supports it, for example when using gridtext as follows: -# `render_as_gtable(..., text_grob = gridtext::richtext_grob)` +# `as_gtable(..., text_grob = gridtext::richtext_grob)` # # classes >: # One or multiple class names equivalent to the html class attributes that will diff --git a/man/as_gtable.Rd b/man/as_gtable.Rd new file mode 100644 index 0000000000..b4aa5c65ba --- /dev/null +++ b/man/as_gtable.Rd @@ -0,0 +1,57 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/export.R +\name{as_gtable} +\alias{as_gtable} +\title{Transform a \strong{gt} table to a \code{gtable} object} +\usage{ +as_gtable(data, plot = FALSE, text_grob = grid::textGrob) +} +\arguments{ +\item{data}{\emph{The gt table data object} + +\verb{obj:} // \strong{required} + +This is the \strong{gt} table object that is commonly created through use of the +\code{\link[=gt]{gt()}} function.} + +\item{plot}{\emph{Render through the graphics device?} + +\verb{scalar} // \emph{default:} \code{FALSE} + +The \code{plot} option determines whether the \code{gtable} object should be rendered +on the graphics device.} + +\item{text_grob}{\code{function} // \emph{default:} \code{grid::textGrob} + +A \code{function} used to draw text. Defaults to \code{grid::textGrob()} but can be +swapped to \code{gridtext::richtext_grob()} to better render HTML content.} +} +\value{ +A \code{gtable} object. +} +\description{ +The \code{as_gtable()} function performs the transformation of a \code{gt_tbl} object +to a \code{gtable} object. +} +\section{Function ID}{ + +13-6 +} + +\section{Function Introduced}{ + +\emph{In Development} +} + +\seealso{ +Other table export functions: +\code{\link{as_latex}()}, +\code{\link{as_raw_html}()}, +\code{\link{as_rtf}()}, +\code{\link{as_word}()}, +\code{\link{extract_body}()}, +\code{\link{extract_cells}()}, +\code{\link{extract_summary}()}, +\code{\link{gtsave}()} +} +\concept{table export functions} diff --git a/man/as_latex.Rd b/man/as_latex.Rd index 0f106f449d..7b02008a9f 100644 --- a/man/as_latex.Rd +++ b/man/as_latex.Rd @@ -79,6 +79,7 @@ just the LaTeX code as a single-element vector. \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, \code{\link{as_word}()}, diff --git a/man/as_raw_html.Rd b/man/as_raw_html.Rd index 4c754742da..df8174e30a 100644 --- a/man/as_raw_html.Rd +++ b/man/as_raw_html.Rd @@ -67,6 +67,7 @@ document but rather an HTML fragment. \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_rtf}()}, \code{\link{as_word}()}, diff --git a/man/as_rtf.Rd b/man/as_rtf.Rd index 88448276bc..6fa0826896 100644 --- a/man/as_rtf.Rd +++ b/man/as_rtf.Rd @@ -85,6 +85,7 @@ with \code{\link[=tab_header]{tab_header()}} and then export the table as RTF co \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_word}()}, diff --git a/man/as_word.Rd b/man/as_word.Rd index cba2d82cd0..0dc1379bd9 100644 --- a/man/as_word.Rd +++ b/man/as_word.Rd @@ -91,6 +91,7 @@ with \code{\link[=tab_header]{tab_header()}} and then export the table as OOXML \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, diff --git a/man/extract_body.Rd b/man/extract_body.Rd index 6d5510748a..c6027cec2a 100644 --- a/man/extract_body.Rd +++ b/man/extract_body.Rd @@ -83,7 +83,7 @@ attachment. } \section{Function ID}{ -13-6 +13-7 } \section{Function Introduced}{ @@ -93,6 +93,7 @@ attachment. \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, diff --git a/man/extract_cells.Rd b/man/extract_cells.Rd index a89c269432..72a5cf8ecb 100644 --- a/man/extract_cells.Rd +++ b/man/extract_cells.Rd @@ -98,7 +98,7 @@ extraction. \section{Function ID}{ -13-8 +13-9 } \section{Function Introduced}{ @@ -108,6 +108,7 @@ extraction. \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, diff --git a/man/extract_summary.Rd b/man/extract_summary.Rd index 785f25cc22..93198d7c46 100644 --- a/man/extract_summary.Rd +++ b/man/extract_summary.Rd @@ -104,7 +104,7 @@ Use the summary list to make a new \strong{gt} table. The key thing is to use \section{Function ID}{ -13-7 +13-8 } \section{Function Introduced}{ @@ -114,6 +114,7 @@ Use the summary list to make a new \strong{gt} table. The key thing is to use \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, diff --git a/man/gtsave.Rd b/man/gtsave.Rd index a851236378..43afd50dc9 100644 --- a/man/gtsave.Rd +++ b/man/gtsave.Rd @@ -144,6 +144,7 @@ With the \code{.docx} extension, we'll get a word/docx document. \seealso{ Other table export functions: +\code{\link{as_gtable}()}, \code{\link{as_latex}()}, \code{\link{as_raw_html}()}, \code{\link{as_rtf}()}, diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 750ef4bf8b..954dceb853 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -308,6 +308,7 @@ reference: - as_latex - as_rtf - as_word + - as_gtable - extract_body - extract_summary - extract_cells diff --git a/tests/testthat/test-render_as_gtable.R b/tests/testthat/test-render_as_gtable.R index 3d634256a9..d8bde7aa01 100644 --- a/tests/testthat/test-render_as_gtable.R +++ b/tests/testthat/test-render_as_gtable.R @@ -42,7 +42,7 @@ test_that("gt_tbls can be rendered as a gtable", { tab_source_note("Source: the pizzaria") %>% tab_footnote("Pineapples not included") - gtable <- render_as_gtable(table) + gtable <- as_gtable(table) expect_snapshot(gtable$layout) @@ -74,7 +74,7 @@ test_that("gtable widths are set appropriately", { ) # Automatic width is width of the text + margins - test <- render_as_gtable(tbl, text_grob = dummy_text) + test <- as_gtable(tbl, text_grob = dummy_text) expect_equal( test$widths, @@ -91,7 +91,7 @@ test_that("gtable widths are set appropriately", { tab_options( table.width = "80%" ) %>% - render_as_gtable(tbl, text_grob = dummy_text) + as_gtable(tbl, text_grob = dummy_text) cell_width <- grid::unit.pmax( grid::unit(100, "pt"), @@ -114,7 +114,7 @@ test_that("gtable widths are set appropriately", { table.width = "80%", table.align = "left" ) %>% - render_as_gtable(tbl, text_grob = dummy_text) + as_gtable(tbl, text_grob = dummy_text) expect_equal( test$widths, @@ -132,7 +132,7 @@ test_that("gtable widths are set appropriately", { table.margin.left = "5%", table.margin.right = "15%" ) %>% - render_as_gtable(tbl, text_grob = dummy_text) + as_gtable(tbl, text_grob = dummy_text) expect_equal( as.numeric(test$widths)[1] * 3,