Skip to content

Instantly share code, notes, and snippets.

@elipousson
Created November 25, 2025 14:45
Show Gist options
  • Select an option

  • Save elipousson/1dd60d8a4b8fb9505ff9bfdd530fc54e to your computer and use it in GitHub Desktop.

Select an option

Save elipousson/1dd60d8a4b8fb9505ff9bfdd530fc54e to your computer and use it in GitHub Desktop.
tt_group <- function(x, ..., by = NULL, hide_group = TRUE) {
x <- dplyr::group_by(x, {{ by }})
vars <- dplyr::group_vars(x)
# Error if more than a single group is supplied
stopifnot(rlang::has_length(vars, 1))
x <- dplyr::arrange(
dplyr::ungroup(x),
.data[[vars]]
)
if (hide_group) {
df <- dplyr::select(
x,
!tidyselect::any_of(vars)
)
}
tinytable::group_tt(
tinytable::tt(df, ...),
i = x[[vars]]
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment