Skip to content

Commit

Permalink
Lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Nov 22, 2024
1 parent fd5017f commit 0e86c84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions R/tbl-format-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ tbl_format_setup.tbl <- function(x, width, ...,
# Number of rows
rows <- nrow(x)

if (is.na(rows)) {
df <- df_head(x, n + 1)
lazy <- is.na(rows)
if (lazy) {
df <- as.data.frame(head(x, n + 1))
if (nrow(df) <= n) {
rows <- nrow(df)
} else {
Expand Down Expand Up @@ -147,7 +148,7 @@ tbl_format_setup.tbl <- function(x, width, ...,

colonnade <- ctl_colonnade(
df,
has_row_id = if (.row_names_info(x) > 0) "*" else TRUE,
has_row_id = if (!lazy && .row_names_info(x) > 0) "*" else TRUE,
width = width,
controller = x,
focus = focus
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/tbl-format-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@
# A data frame: ?? x 3
<tbl_format_body(setup)>
Girth Height Volume
* <dbl> <dbl> <dbl>
<dbl> <dbl> <dbl>
1 8.3 70 10.3
2 8.6 65 10.3
3 8.8 63 10.2
Expand All @@ -1439,7 +1439,7 @@
# A data frame: ?? x 3
<tbl_format_body(setup)>
Girth Height Volume
* <dbl> <dbl> <dbl>
<dbl> <dbl> <dbl>
1 8.3 70 10.3
2 8.6 65 10.3
3 8.8 63 10.2
Expand All @@ -1459,7 +1459,7 @@
# A data frame: ?? x 3
<tbl_format_body(setup)>
Girth Height Volume
* <dbl> <dbl> <dbl>
<dbl> <dbl> <dbl>
1 8.3 70 10.3
2 8.6 65 10.3
3 8.8 63 10.2
Expand Down

0 comments on commit 0e86c84

Please sign in to comment.