Skip to content

Add row group id as an argument to tab_row_group()#699

Merged
rich-iannone merged 73 commits intomasterfrom
row-group-id
Apr 5, 2021
Merged

Add row group id as an argument to tab_row_group()#699
rich-iannone merged 73 commits intomasterfrom
row-group-id

Conversation

@rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Dec 10, 2020

This PR seeks to do what #665 did recently, which is to require and use IDs for different row groups. The function signature for tab_row_group() will be similar to that of the analogous tab_spanner():

tab_row_group(
  data,
  label = NULL,
  rows = NULL,
  id = label,
  others = NULL
)

This is not the only way to specify row groups in a gt table. Here is a breakdown of the three different ways to include them:

  1. with grouped data given to gt(); group labels are composed by the group column names being pasted together, each separated by _
  2. using the groupname_col arg in gt(); we can only choose one column so flexibility in grouping is purposefully limited compared to method (1)
  3. by use of the tab_row_group function. This is used past the initial gt() step.

Aside from introducing IDs here, this PR aims to fix a number of known bugs along the way.

Fixes: #671
Fixes: #675
Fixes: #717

* master:
  do html_preserve hack for caption only when html_preserve is active
  Add tests; process_text now handles htmltools::tags, tagList
  Get table caption rewriting working for bookdown
  Update render_as_html.R
  Add the `create_caption_component_h()` fn
  Update helper-gt_attr_expectations.R
  Create TODOs and basics caption in HTML tables
  Update gt.Rd
  Augment the `dt_options_tbl` with `table_caption`
  Add `caption` arg in `gt()`
  Add the `caption` arg to `gt()`
  Add the `cols_merge_n_pct()` function (#683)
@rich-iannone rich-iannone changed the title Row group Add row group id as an argument to tab_row_group() Dec 10, 2020
* master: (26 commits)
  Remove irrelevant tests
  Update README
  Update license year info
  Update testthat tests
  Update _pkgdown.yml
  Update `cols_unhide()` to new tidyselect API
  Update test-table_parts.R
  Update PNG images for examples
  Update cols_unhide.Rd
  Update doc examples for `cols_unhide()`
  Update documentation with roxygen
  Add to NAMESPACE
  Add `dt_boxhead_set_not_hidden()` util fcn
  Modify internal documentation
  Add the `cols_unhide()` function
  Update intro-creating-gt-tables.Rmd
  Update gt-datasets.Rmd
  Update creating-summary-lines.Rmd
  Update case-study-gtcars.Rmd
  Convert columns to tidyselect semantics (#718)
  ...
@jcheng5
Copy link
Member

jcheng5 commented Apr 2, 2021

Just to note a limitation on the column splitting logic, if delim contains "\\E" then the behavior will be wrong.

split_at_first_delim <- function(delim, str) {
  delim <- gsub("\\E", "\\\\E", delim, fixed = TRUE)
  m <- regexec(perl = TRUE,
    paste0(
      "^(.*?)\\Q", delim, "\\E(.*)$"
    ),
    str
  )
  regmatches(str, m)
}

split_at_first_delim("\\E", "foEo\\E.bar")  # expected: foEo|.bar
split_at_first_delim("\\", "foo\\bar")      # expected: foo|bar
split_at_first_delim("\\\\E", "foo\\\\Ebar")      # expected: foo|bar

We could fix this, or, simply detect \\E in the delim and throw. I don't think anyone will do this in good faith, but this will prevent any weird attack vectors(?).

jcheng5
jcheng5 previously approved these changes Apr 5, 2021
jcheng5
jcheng5 previously approved these changes Apr 5, 2021
@rich-iannone rich-iannone merged commit 94f17cb into master Apr 5, 2021
@rich-iannone rich-iannone deleted the row-group-id branch April 5, 2021 19:56
rich-iannone added a commit that referenced this pull request Apr 5, 2021
* master:
  Add row group `id` as an argument to `tab_row_group()` (#699)
rich-iannone added a commit that referenced this pull request Apr 5, 2021
* master:
  Add row group `id` as an argument to `tab_row_group()` (#699)
@rich-iannone rich-iannone linked an issue Apr 27, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants