From 9fa6617798ae9654328e2b83c439bb3afb0a0a1e Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 14 Aug 2024 19:40:09 -0400 Subject: [PATCH 1/4] Minor tweaks --- R/dt_has_built.R | 7 ++++--- R/extract.R | 4 ++-- R/utils_render_common.R | 8 +------- R/utils_render_html.R | 2 +- tests/performance-monitoring/dplyr-known-good.md | 2 +- tests/performance-monitoring/dplyr.qmd | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/R/dt_has_built.R b/R/dt_has_built.R index 89dce80156..ee267377c1 100644 --- a/R/dt_has_built.R +++ b/R/dt_has_built.R @@ -42,13 +42,14 @@ dt_has_built <- function(data) { #nocov start -dt_has_built_assert <- function(data) { +dt_has_built_assert <- function(data, call = rlang::caller_env()) { - if (!dt_has_built(data = data)) { + if (!dt_has_built(data)) { cli::cli_abort(c( "The build hasn't yet occurred.", "*" = "Call `build_data()` before retrieving." - )) + ), + call = caller_env()) } } diff --git a/R/extract.R b/R/extract.R index f25e2d3fd9..194725c70b 100644 --- a/R/extract.R +++ b/R/extract.R @@ -260,7 +260,7 @@ extract_summary <- function(data) { cli::cli_abort(c( "There is no summary list to extract.", - "*" = "Use the `{.help [summary_rows](gt::summary_rows)}()` / + "*" = "Use the `{.help [summary_rows](gt::summary_rows)}()` / `{.help [grand_summary_rows](gt::grand_summary_rows)}()` functions to generate summaries." )) @@ -409,7 +409,7 @@ extract_cells <- function( data = data ) - if (!dt_has_built_get(data)) { + if (!dt_has_built(data)) { # # Partially build the gt table using the resolved `output` as the # rendering context; this formats the body cells and applies merging diff --git a/R/utils_render_common.R b/R/utils_render_common.R index dd643be450..8b7b99d92b 100644 --- a/R/utils_render_common.R +++ b/R/utils_render_common.R @@ -744,13 +744,7 @@ get_number_of_visible_data_columns <- function(data) { get_effective_number_of_columns <- function(data) { # Check if the table has been built, return an error if that's not the case - if (!dt_has_built(data = data)) { - - cli::cli_abort( - "The `get_effective_number_of_columns()` function can only be used on - gt objects that have tables 'built'." - ) - } + dt_has_built_assert(data = data) # Obtain the number of visible columns in the built table n_data_cols <- get_number_of_visible_data_columns(data = data) diff --git a/R/utils_render_html.R b/R/utils_render_html.R index 9f72f799bc..c20fe61033 100644 --- a/R/utils_render_html.R +++ b/R/utils_render_html.R @@ -1192,7 +1192,7 @@ create_body_component_h <- function(data) { ) summary[[1]] <- - htmltools::HTML(gsub("^", paste0("", group_col_td), as.character(summary[[1]]))) + htmltools::HTML(sub("^", paste0("", group_col_td), as.character(summary[[1]]))) } summary diff --git a/tests/performance-monitoring/dplyr-known-good.md b/tests/performance-monitoring/dplyr-known-good.md index 5182562531..2d7fcc4c71 100644 --- a/tests/performance-monitoring/dplyr-known-good.md +++ b/tests/performance-monitoring/dplyr-known-good.md @@ -3,7 +3,7 @@ title: "dplyr <-> data.table" subtitle: "Notes I took while learning to use data.table" author: - name: "Marc-Aurèle Rivière" - url: https://ma-riviere.me + url: https://ma-riviere.com orcid: 0000-0002-5108-3382 date: "2022-05-19" editor: source diff --git a/tests/performance-monitoring/dplyr.qmd b/tests/performance-monitoring/dplyr.qmd index 82ba65c86a..3d45242d51 100644 --- a/tests/performance-monitoring/dplyr.qmd +++ b/tests/performance-monitoring/dplyr.qmd @@ -3,7 +3,7 @@ title: "dplyr <-> data.table" subtitle: "Notes I took while learning to use data.table" author: - name: "Marc-Aurèle Rivière" - url: https://ma-riviere.me + url: https://ma-riviere.com orcid: 0000-0002-5108-3382 date: "2022-05-19" editor: source From 72776761042159a0ef516bf831cfb7a3e2b8df3f Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 15 Aug 2024 08:25:15 -0400 Subject: [PATCH 2/4] Force footnote to be supplied to avoid cryptic message later --- R/tab_footnote.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/tab_footnote.R b/R/tab_footnote.R index 895f5bf486..ad517c2445 100644 --- a/R/tab_footnote.R +++ b/R/tab_footnote.R @@ -367,7 +367,7 @@ tab_footnote <- function( ) { placement <- rlang::arg_match(placement) - + rlang::check_required(footnote) # Perform input object validation stop_if_not_gt_tbl(data = data) @@ -497,7 +497,7 @@ set_footnote.cells_column_labels <- function( placement ) { - resolved <- + resolved <- resolve_cells_column_labels( data = data, object = loc, @@ -598,7 +598,7 @@ set_footnote.cells_body <- function( placement ) { - resolved <- + resolved <- resolve_cells_body( data = data, object = loc, From 63bf59133ad2b146ef5c65c46683872cf9d21480 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 15 Aug 2024 08:33:39 -0400 Subject: [PATCH 3/4] Re-export where all_of, any_of from tidyselect. --- NAMESPACE | 6 ++++++ NEWS.md | 1 + R/reexports.R | 34 +++++++++++++++++++++++++--------- R/utils_pipe.R | 35 ----------------------------------- man/pipe.Rd | 12 ------------ man/reexports.Rd | 8 +++++++- 6 files changed, 39 insertions(+), 57 deletions(-) delete mode 100644 R/utils_pipe.R delete mode 100644 man/pipe.Rd diff --git a/NAMESPACE b/NAMESPACE index c2967e7218..164120d489 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,8 @@ S3method(to_output_location,default) S3method(to_output_location,output_relative) export("%>%") export(adjust_luminance) +export(all_of) +export(any_of) export(as_gtable) export(as_latex) export(as_raw_html) @@ -244,11 +246,14 @@ export(vec_fmt_scientific) export(vec_fmt_spelled_num) export(vec_fmt_time) export(web_image) +export(where) import(rlang) importFrom(dplyr,vars) importFrom(htmltools,as.tags) importFrom(htmltools,css) importFrom(magrittr,"%>%") +importFrom(tidyselect,all_of) +importFrom(tidyselect,any_of) importFrom(tidyselect,contains) importFrom(tidyselect,ends_with) importFrom(tidyselect,everything) @@ -256,6 +261,7 @@ importFrom(tidyselect,matches) importFrom(tidyselect,num_range) importFrom(tidyselect,one_of) importFrom(tidyselect,starts_with) +importFrom(tidyselect,where) importFrom(xml2,`xml_attr<-`) importFrom(xml2,`xml_text<-`) importFrom(xml2,as_xml_document) diff --git a/NEWS.md b/NEWS.md index a022aef846..9dfee73e62 100644 --- a/NEWS.md +++ b/NEWS.md @@ -43,6 +43,7 @@ * Fixed an issue where `tab_spanner_delim()` would fail to resolve a duplicate id (@olivroy, #1821). +* `tidyselect::where()`, `tidyselect::all_of()`, `tidyselect::any_of()` are now re-exported by gt. # gt 0.11.0 ## New features diff --git a/R/reexports.R b/R/reexports.R index 477d649e69..16144a46b3 100644 --- a/R/reexports.R +++ b/R/reexports.R @@ -21,11 +21,6 @@ # #------------------------------------------------------------------------------# - -#' @importFrom dplyr vars -#' @export -dplyr::vars - #' @importFrom tidyselect starts_with #' @export tidyselect::starts_with @@ -42,10 +37,6 @@ tidyselect::contains #' @export tidyselect::matches -#' @importFrom tidyselect one_of -#' @export -tidyselect::one_of - #' @importFrom tidyselect everything #' @export tidyselect::everything @@ -54,6 +45,31 @@ tidyselect::everything #' @export tidyselect::num_range +#' @importFrom tidyselect all_of +#' @export +tidyselect::all_of + +#' @importFrom tidyselect any_of +#' @export +tidyselect::any_of + +#' @importFrom tidyselect where +#' @export +tidyselect::where + #' @importFrom htmltools css #' @export htmltools::css + +#' @importFrom magrittr %>% +#' @export +magrittr::`%>%` + +# TODO Avoid reexporting those helpers eventually ----- +#' @importFrom dplyr vars +#' @export +dplyr::vars + +#' @importFrom tidyselect one_of +#' @export +tidyselect::one_of diff --git a/R/utils_pipe.R b/R/utils_pipe.R deleted file mode 100644 index 8ff4afc598..0000000000 --- a/R/utils_pipe.R +++ /dev/null @@ -1,35 +0,0 @@ -#------------------------------------------------------------------------------# -# -# /$$ -# | $$ -# /$$$$$$ /$$$$$$ -# /$$__ $$|_ $$_/ -# | $$ \ $$ | $$ -# | $$ | $$ | $$ /$$ -# | $$$$$$$ | $$$$/ -# \____ $$ \___/ -# /$$ \ $$ -# | $$$$$$/ -# \______/ -# -# This file is part of the 'rstudio/gt' project. -# -# Copyright (c) 2018-2024 gt authors -# -# For full copyright and license information, please look at -# https://gt.rstudio.com/LICENSE.html -# -#------------------------------------------------------------------------------# - - -#' Pipe operator -#' -#' See \code{magrittr::\link[magrittr]{\%>\%}} for details. -#' -#' @name %>% -#' @rdname pipe -#' @keywords internal -#' @export -#' @importFrom magrittr %>% -#' @usage lhs \%>\% rhs -NULL diff --git a/man/pipe.Rd b/man/pipe.Rd deleted file mode 100644 index cb665359fe..0000000000 --- a/man/pipe.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils_pipe.R -\name{\%>\%} -\alias{\%>\%} -\title{Pipe operator} -\usage{ -lhs \%>\% rhs -} -\description{ -See \code{magrittr::\link[magrittr]{\%>\%}} for details. -} -\keyword{internal} diff --git a/man/reexports.Rd b/man/reexports.Rd index 40d9d03898..6f556163ee 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -11,7 +11,11 @@ \alias{one_of} \alias{everything} \alias{num_range} +\alias{all_of} +\alias{any_of} +\alias{where} \alias{css} +\alias{\%>\%} \title{Objects exported from other packages} \keyword{internal} \description{ @@ -23,6 +27,8 @@ below to see their documentation. \item{htmltools}{\code{\link[htmltools]{css}}} - \item{tidyselect}{\code{\link[tidyselect:starts_with]{contains}}, \code{\link[tidyselect:starts_with]{ends_with}}, \code{\link[tidyselect]{everything}}, \code{\link[tidyselect:starts_with]{matches}}, \code{\link[tidyselect:starts_with]{num_range}}, \code{\link[tidyselect]{one_of}}, \code{\link[tidyselect]{starts_with}}} + \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}} + + \item{tidyselect}{\code{\link[tidyselect]{all_of}}, \code{\link[tidyselect:all_of]{any_of}}, \code{\link[tidyselect:starts_with]{contains}}, \code{\link[tidyselect:starts_with]{ends_with}}, \code{\link[tidyselect]{everything}}, \code{\link[tidyselect:starts_with]{matches}}, \code{\link[tidyselect:starts_with]{num_range}}, \code{\link[tidyselect]{one_of}}, \code{\link[tidyselect]{starts_with}}, \code{\link[tidyselect]{where}}} }} From ca5e5b5c93333803068f6d722ed39fa19616656d Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 15 Aug 2024 09:02:25 -0400 Subject: [PATCH 4/4] Fix condition + update snapshot --- R/tab_footnote.R | 5 +++-- tests/testthat/_snaps/utils_render_grid.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/tab_footnote.R b/R/tab_footnote.R index ad517c2445..9829133d8e 100644 --- a/R/tab_footnote.R +++ b/R/tab_footnote.R @@ -366,11 +366,12 @@ tab_footnote <- function( placement = c("auto", "right", "left") ) { - placement <- rlang::arg_match(placement) - rlang::check_required(footnote) # Perform input object validation stop_if_not_gt_tbl(data = data) + placement <- rlang::arg_match(placement) + rlang::check_required(footnote) + if (is.null(locations)) { # We need to invoke `dt_footnotes_add()` here (and not use diff --git a/tests/testthat/_snaps/utils_render_grid.md b/tests/testthat/_snaps/utils_render_grid.md index 82f7662760..d9f1447028 100644 --- a/tests/testthat/_snaps/utils_render_grid.md +++ b/tests/testthat/_snaps/utils_render_grid.md @@ -1,4 +1,4 @@ -# create_columns_component_g creates columns and spanners +# create_columns_component_g() creates columns and spanners Code test