diff --git a/NAMESPACE b/NAMESPACE index bd642ddc3..0a0783231 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,6 +76,7 @@ S3method(tbl_format_footer,tbl) S3method(tbl_format_header,pillar_tbl_format_setup) S3method(tbl_format_header,tbl) S3method(tbl_format_setup,tbl) +S3method(tbl_nrow,tbl) S3method(tbl_sum,default) S3method(tbl_sum,tbl) S3method(type_sum,Surv) @@ -155,6 +156,7 @@ export(tbl_format_body) export(tbl_format_footer) export(tbl_format_header) export(tbl_format_setup) +export(tbl_nrow) export(tbl_sum) export(type_sum) import(lifecycle) diff --git a/R/tbl-format-setup.R b/R/tbl-format-setup.R index 9311addc0..b8ba2b146 100644 --- a/R/tbl-format-setup.R +++ b/R/tbl-format-setup.R @@ -76,7 +76,7 @@ tbl_format_setup <- function( width <- get_width_print(width) - n <- get_n_print(n, nrow(x)) + n <- get_n_print(n, tbl_nrow(x)) max_extra_cols <- get_max_extra_cols(max_extra_cols) max_footer_lines <- get_max_footer_lines(max_footer_lines) @@ -112,7 +112,7 @@ tbl_format_setup.tbl <- function(x, width, ..., "!!!!DEBUG tbl_format_setup.tbl()" # Number of rows - rows <- nrow(x) + rows <- tbl_nrow(x) lazy <- is.na(rows) if (lazy) { @@ -183,6 +183,23 @@ tbl_format_setup.tbl <- function(x, width, ..., ) } +#' Number of rows in a tbl object +#' +#' This generic will be called by [tbl_format_setup()] to determine the number +#' of rows in a tbl object. +#' +#' @param x A tbl object. +#' @export +tbl_nrow <- function(x, ...) { + UseMethod("tbl_nrow") +} + +#' @export +tbl_nrow.tbl <- function(x, ...) { + nrow(x) +} + + #' Construct a setup object for formatting #' #' @description diff --git a/_pkgdown.yml b/_pkgdown.yml index 6d062d5d5..8a0cf2960 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -21,6 +21,7 @@ reference: - ctl_new_pillar - ctl_new_pillar_list - tbl_sum + - tbl_nrow - glimpse - format_glimpse - title: Formatting pillars diff --git a/man/tbl_nrow.Rd b/man/tbl_nrow.Rd new file mode 100644 index 000000000..2082efd57 --- /dev/null +++ b/man/tbl_nrow.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tbl-format-setup.R +\name{tbl_nrow} +\alias{tbl_nrow} +\title{Number of rows in a tbl object} +\usage{ +tbl_nrow(x, ...) +} +\arguments{ +\item{x}{A tbl object.} +} +\description{ +This generic will be called by \code{\link[=tbl_format_setup]{tbl_format_setup()}} to determine the number +of rows in a tbl object. +}