Skip to content

Commit

Permalink
tbl_nrow()
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Nov 22, 2024
1 parent 0e86c84 commit 839e0e0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions R/tbl-format-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reference:
- ctl_new_pillar
- ctl_new_pillar_list
- tbl_sum
- tbl_nrow
- glimpse
- format_glimpse
- title: Formatting pillars
Expand Down
15 changes: 15 additions & 0 deletions man/tbl_nrow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 839e0e0

Please sign in to comment.