Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New tbl_nrow() to support lazy data frames #679

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 21 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,25 @@ 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.
#' @inheritParams rlang::args_dots_empty
#' @export
tbl_nrow <- function(x, ...) {
check_dots_empty0(...)
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
17 changes: 17 additions & 0 deletions man/tbl_nrow.Rd

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

Loading