R/dim.R

Defines functions dim.gtsummary

Documented in dim.gtsummary

#' gtsummary table dimension
#'
#' @description
#' Returns the dimension of a gtsummary table, that is, the number of rows
#' and the number of un-hidden columns.
#'
#' `nrow()` calls `dim()`; therefore, `nrow()` will also work on gtsummary tables.
#'
#' @param x (`gtsummary`)\cr
#'  a 'gtsummary' table
#'
#' @returns integer vector
#' @export
#' @keywords internal
#'
#' @examples
#' tbl <- tbl_summary(trial, include = age, by = trt)
#'
#' dim(tbl)
#' nrow(tbl)
dim.gtsummary <- function(x) {
  # select only unhidden columns
  columns <- x$table_styling$header[!x$table_styling$header$hide,]$column

  dim(x$table_body[columns])
}

Try the gtsummary package in your browser

Any scripts or data that you put into this service are public.

gtsummary documentation built on Aug. 26, 2026, 9:07 a.m.