Skip to content

Commit

Permalink
Combine files
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Jul 28, 2021
1 parent 5370d59 commit 61b18c3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 81 deletions.
55 changes: 55 additions & 0 deletions R/options.R
Expand Up @@ -138,3 +138,58 @@ pillar_options <- list2(
getOption("pillar.bidi", default = FALSE)
),
)

tibble_opt <- function(x, default) {
x_tibble <- paste0("tibble.", x)
res <- getOption(x_tibble)
if (!is.null(res)) {
return(res)
}

x_dplyr <- paste0("dplyr.", x)
res <- getOption(x_dplyr)
if (!is.null(res)) {
return(res)
}

default
}

get_width_print <- function(width) {
if (!is.null(width)) {
return(width)
}

get_pillar_option_width()
}

get_width_glimpse <- function(width) {
width <- get_width_print(width)

if (is.finite(width)) {
width
} else {
getOption("width")
}
}

get_n_print <- function(n, rows) {
if (!is.null(n) && n >= 0) {
return(n)
}

if (is.na(rows) || rows > get_pillar_option_print_max()) {
get_pillar_option_print_min()
} else {
rows
}
}

get_max_extra_cols <- function(max_extra_cols) {
# FIXME: Deprecate
if (!is.null(max_extra_cols) && max_extra_cols >= 0) {
return(max_extra_cols)
}

get_pillar_option_max_extra_cols()
}
54 changes: 0 additions & 54 deletions R/tibble-opt.R

This file was deleted.

27 changes: 27 additions & 0 deletions tests/testthat/test-options.R
Expand Up @@ -166,3 +166,30 @@ test_that("max_dec_width", {
expect_equal(get_pillar_option_max_dec_width(), orig)
})

test_that("print.tbl ignores max.print option", {
trees2 <- as_tbl(trees)
expect_output(
withr::with_options(list(max.print = 3), print(trees2)),
capture_output(print(trees2)),
fixed = TRUE
)
})

test_that("print.tbl uses tibble.width option", {
mtcars2 <- as_tbl(mtcars)
expect_output(
withr::with_options(list(tibble.width = 40, dplyr.width = 50, width = 60), print(mtcars2)),
capture_output(print(mtcars2, width = 40)),
fixed = TRUE
)
expect_output(
withr::with_options(list(dplyr.width = 50, width = 60), print(mtcars2)),
capture_output(print(mtcars2, width = 50)),
fixed = TRUE
)
expect_output(
withr::with_options(list(width = 60), print(mtcars2)),
capture_output(print(mtcars2, width = 60)),
fixed = TRUE
)
})
27 changes: 0 additions & 27 deletions tests/testthat/test-tibble-opt.R

This file was deleted.

0 comments on commit 61b18c3

Please sign in to comment.