diff --git a/R/step.R b/R/step.R index c6191510..d07293ef 100644 --- a/R/step.R +++ b/R/step.R @@ -176,7 +176,11 @@ pull.dtplyr_step <- function(.data, var = -1, name = NULL, ...) { } #' @export -print.dtplyr_step <- function(x, ...) { +print.dtplyr_step <- function(x, + ..., + n = 6, + max_extra_cols = NULL, + max_footer_lines = NULL) { dt <- as.data.table(x) cat_line(cli::style_bold("Source: "), "local data table ", dplyr::dim_desc(dt)) @@ -193,7 +197,14 @@ print.dtplyr_step <- function(x, ...) { cat_line(cli::style_bold("Call: "), expr_text(dt_call(x))) } cat_line() - cat_line(format(as_tibble(dt, .name_repair = "minimal"), n = 6)[-1]) # Hack to remove "A tibble" line + cat_line( + format( + as_tibble(dt, .name_repair = "minimal"), + n = n, + max_extra_cols = max_extra_cols, + max_footer_lines = max_footer_lines + )[-1] # Hack to remove "A tibble" line + ) cat_line() cat_line(cli::col_silver( "# Use as.data.table()/as.data.frame()/as_tibble() to access results" diff --git a/tests/testthat/_snaps/step.md b/tests/testthat/_snaps/step.md index c0af0a27..56ba264f 100644 --- a/tests/testthat/_snaps/step.md +++ b/tests/testthat/_snaps/step.md @@ -56,3 +56,59 @@ # Use as.data.table()/as.data.frame()/as_tibble() to access results +# can print using n/max_extra_cols/max_footer_lines, #464, + + Code + dt <- letters %>% lapply(function(.x) tibble(!!.x := 1:10)) %>% bind_cols() %>% + lazy_dt("DT") + print(dt, n = 3) + Output + Source: local data table [10 x 26] + Call: DT + + a b c d e f g h i j k l m + + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 + # i 7 more rows + # i 13 more variables: n , o , p , q , r , s , + # t , u , v , w , x , y , z + + # Use as.data.table()/as.data.frame()/as_tibble() to access results + Code + print(dt, max_extra_cols = 3) + Output + Source: local data table [10 x 26] + Call: DT + + a b c d e f g h i j k l m + + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 + 4 4 4 4 4 4 4 4 4 4 4 4 4 4 + 5 5 5 5 5 5 5 5 5 5 5 5 5 5 + 6 6 6 6 6 6 6 6 6 6 6 6 6 6 + # i 4 more rows + # i 13 more variables: n , o , p , ... + + # Use as.data.table()/as.data.frame()/as_tibble() to access results + Code + print(dt, max_footer_lines = 1) + Output + Source: local data table [10 x 26] + Call: DT + + a b c d e f g h i j k l m + + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 + 4 4 4 4 4 4 4 4 4 4 4 4 4 4 + 5 5 5 5 5 5 5 5 5 5 5 5 5 5 + 6 6 6 6 6 6 6 6 6 6 6 6 6 6 + # i 4 more rows + + # Use as.data.table()/as.data.frame()/as_tibble() to access results + diff --git a/tests/testthat/test-step.R b/tests/testthat/test-step.R index 88a147c8..61b8315f 100644 --- a/tests/testthat/test-step.R +++ b/tests/testthat/test-step.R @@ -29,6 +29,18 @@ test_that("has useful display methods", { }) }) +test_that("can print using n/max_extra_cols/max_footer_lines, #464, ", { + expect_snapshot({ + dt <- letters %>% + lapply(function(.x) tibble(!!.x := 1:10)) %>% + bind_cols() %>% + lazy_dt("DT") + print(dt, n = 3) + print(dt, max_extra_cols = 3) + print(dt, max_footer_lines = 1) + }) +}) + test_that("can evaluate to any data frame type", { dt <- lazy_dt(mtcars, "DT")