Skip to content

Commit

Permalink
chore: Refactorings to improve duckplyr support (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Nov 22, 2024
1 parent 809a9d6 commit c3b3076
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
1 change: 0 additions & 1 deletion .github/dep-suggests-matrix.json

This file was deleted.

1 change: 0 additions & 1 deletion .github/versions-matrix.json

This file was deleted.

2 changes: 1 addition & 1 deletion R/tbl-format-footer.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ format_footer <- function(x, setup) {
}

format_footer_extra_rows <- function(x, setup) {
if (ncol(setup$x) != 0) {
if (length(setup$df) != 0) {
if (is.na(setup$rows_missing)) {
c("more", "rows")
} else if (setup$rows_missing > 0) {
Expand Down
46 changes: 32 additions & 14 deletions R/tbl-format-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@
#' @export
#' @examplesIf rlang::is_installed("palmerpenguins")
#' tbl_format_setup(palmerpenguins::penguins)
tbl_format_setup <- function(x, width = NULL, ...,
n = NULL, max_extra_cols = NULL,
max_footer_lines = NULL,
focus = NULL) {
tbl_format_setup <- function(
x,
width = NULL,
...,
n = NULL,
max_extra_cols = NULL,
max_footer_lines = NULL,
focus = NULL
) {
"!!!!DEBUG tbl_format_setup()"

width <- get_width_print(width)
Expand All @@ -79,8 +84,12 @@ tbl_format_setup <- function(x, width = NULL, ...,
# Calls UseMethod("tbl_format_setup"),
# allows using default values in S3 dispatch
out <- tbl_format_setup_dispatch(
x, width, ...,
n = n, max_extra_cols = max_extra_cols, max_footer_lines = max_footer_lines,
x,
width,
...,
n = n,
max_extra_cols = max_extra_cols,
max_footer_lines = max_footer_lines,
focus = focus
)
return(out)
Expand All @@ -105,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 @@ -138,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 Expand Up @@ -203,11 +213,19 @@ tbl_format_setup.tbl <- function(x, width, ...,
#' in the body.
#'
#' @keywords internal
new_tbl_format_setup <- function(x, df, width, tbl_sum, body,
rows_missing, rows_total,
extra_cols, extra_cols_total,
max_footer_lines,
abbrev_cols) {
new_tbl_format_setup <- function(
x,
df,
width,
tbl_sum,
body,
rows_missing,
rows_total,
extra_cols,
extra_cols_total,
max_footer_lines,
abbrev_cols
) {
trunc_info <- list(
x = x,
df = df,
Expand Down
15 changes: 9 additions & 6 deletions R/tbl-format.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ format.tbl <- function(x, width = NULL, ...,
)
}

format_tbl <- function(x, width = NULL, ...,
n_extra = NULL,
n = NULL, max_extra_cols = NULL, max_footer_lines = NULL) {
format_tbl <- function(
x,
width = NULL,
...,
n_extra = NULL,
n = NULL,
max_extra_cols = NULL,
max_footer_lines = NULL
) {
check_dots_empty(action = signal)

if (!is.null(n_extra)) {
deprecate_stop("1.6.2", "pillar::format(n_extra = )", "pillar::format(max_extra_cols = )")
if (is.null(max_extra_cols)) {
max_extra_cols <- n_extra
}
}

# Reset local cache for each new output
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 c3b3076

Please sign in to comment.