Skip to content

Feature/sub tfl#27

Merged
billdenney merged 3 commits intomainfrom
feature/sub-tfl
Apr 29, 2026
Merged

Feature/sub tfl#27
billdenney merged 3 commits intomainfrom
feature/sub-tfl

Conversation

@billdenney
Copy link
Copy Markdown
Member

No description provided.

billdenney and others added 2 commits April 28, 2026 21:41
tfl_table() and export_tfl.ggtibble() now accept a sub_tfl character
vector that splits the output into one sub-table or sub-figure per
unique combination of values, removing those columns from the rendered
body and appending them to the caption as "label: value; label: value".
Formatting is controlled by sub_tfl_sep, sub_tfl_collapse, and
sub_tfl_prefix.

Sub-table ordering follows factor levels for factor columns and
first-appearance order otherwise; the first column of sub_tfl varies
outermost. sub_tfl columns may overlap with dplyr::group_vars(x), in
which case they are promoted from row-header rendering to the caption.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds section 13 with a worked example, the formatting argument table,
ordering rules, group_vars overlap behaviour, and a pointer to the
ggtibble equivalent. Renumbers the complete-example section to 14.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread R/ggtibble.R Outdated
paste(bad, collapse = ", ")
))
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

Comment thread R/ggtibble.R Outdated
))
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
checkmate::assert_string(sub_tfl_collapse, .var.name = "sub_tfl_collapse")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

Comment thread R/ggtibble.R Outdated
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
checkmate::assert_string(sub_tfl_collapse, .var.name = "sub_tfl_collapse")
checkmate::assert_string(sub_tfl_prefix, .var.name = "sub_tfl_prefix")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

Comment thread R/sub_tfl.R Outdated
# first-appearance order. sub_tfl[1] varies outermost (slowest).
#' @keywords internal
.compute_sub_tfl_groups <- function(data, sub_tfl) {
ord_vals <- lapply(sub_tfl, function(col) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use nested functions, even in lapply. Create a separate function and call it with all required arguments.

Comment thread R/sub_tfl.R Outdated
names(ord_vals) <- sub_tfl

# Build combos with sub_tfl[1] outermost.
combos <- lapply(ord_vals[[1L]], function(v) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not require a nested function. Please do not use one. Just use stats::setNames() directly.

Comment thread R/table_pagelist.R Outdated
})
pages <- c(pages, sub_pages)
}
return(pages)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always omit the extraneous return() call.

Comment thread R/tfl_table.R Outdated
))
}
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

Comment thread R/tfl_table.R Outdated
}
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
checkmate::assert_string(sub_tfl_collapse, .var.name = "sub_tfl_collapse")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

Comment thread R/tfl_table.R Outdated
}
checkmate::assert_string(sub_tfl_sep, .var.name = "sub_tfl_sep")
checkmate::assert_string(sub_tfl_collapse, .var.name = "sub_tfl_collapse")
checkmate::assert_string(sub_tfl_prefix, .var.name = "sub_tfl_prefix")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert len = 1

- Replace nested anonymous functions in lapply/vapply with named
  top-level helpers (.ordered_unique_values, .named_one_value,
  .colspec_not_in, .format_sub_tfl_pair, .format_ggtibble_sub_tfl_pair,
  .ggtibble_row_pagespec, .attach_page_caption).
- Tighten string assertions to assert_character(..., len = 1L,
  any.missing = FALSE) so the length-1 contract is explicit.
- Restructure tfl_table_to_pagelist() as an if/else dispatch over two
  helpers (.tfl_table_to_pagelist_default and ..._sub_tfl) instead of an
  early return.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@billdenney billdenney merged commit 53d8f3a into main Apr 29, 2026
9 checks passed
@billdenney billdenney deleted the feature/sub-tfl branch April 29, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant