From 8bb9641ab6e6aa9b1e12bea311599967cde6afe2 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:07:03 +0200 Subject: [PATCH] Move {tibble} to suggests (#5990) * don't use `tibble()` in code * remove `tibble()` from examples/tests * redocument * add news bullet --- DESCRIPTION | 2 +- NAMESPACE | 1 - NEWS.md | 1 + R/facet-.R | 2 +- R/position-stack.R | 12 ++++----- R/summarise-plot.R | 4 +-- R/utilities.R | 4 --- man/position_stack.Rd | 12 ++++----- tests/testthat/test-geom-quantile.R | 2 +- tests/testthat/test-geom-tile.R | 9 +++---- tests/testthat/test-scale-discrete.R | 7 +++-- tests/testthat/test-sec-axis.R | 2 +- tests/testthat/test-stat-align.R | 39 +++++++++------------------- 13 files changed, 36 insertions(+), 61 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a14039f20..b4cd9ec950 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,7 +42,6 @@ Imports: rlang (>= 1.1.0), scales (>= 1.3.0), stats, - tibble, vctrs (>= 0.6.0), withr (>= 2.5.0) Suggests: @@ -67,6 +66,7 @@ Suggests: sf (>= 0.7-3), svglite (>= 2.1.2), testthat (>= 3.1.5), + tibble, vdiffr (>= 1.0.6), xml2 Enhances: diff --git a/NAMESPACE b/NAMESPACE index ea62e9b076..197845db89 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -735,7 +735,6 @@ importFrom(grid,unit) importFrom(lifecycle,deprecated) importFrom(scales,alpha) importFrom(stats,setNames) -importFrom(tibble,tibble) importFrom(utils,.DollarNames) importFrom(utils,head) importFrom(utils,tail) diff --git a/NEWS.md b/NEWS.md index 6a66ca97d4..b4636c5166 100644 --- a/NEWS.md +++ b/NEWS.md @@ -159,6 +159,7 @@ (@teunbrand, #4584). * `theme_classic()` now has black ticks and text instead of dark gray. In addition, `theme_classic()`'s axis line end is `"square"` (@teunbrand, #5978). +* {tibble} is now suggested instead of imported (@teunbrand, #5986) # ggplot2 3.5.1 diff --git a/R/facet-.R b/R/facet-.R index a5e6f35101..2e349f6f97 100644 --- a/R/facet-.R +++ b/R/facet-.R @@ -564,7 +564,7 @@ is_facets <- function(x) { # but that seems like a reasonable tradeoff. eval_facets <- function(facets, data, possible_columns = NULL) { vars <- compact(lapply(facets, eval_facet, data, possible_columns = possible_columns)) - data_frame0(tibble::as_tibble(vars)) + data_frame0(!!!vars) } eval_facet <- function(facet, data, possible_columns = NULL) { # Treat the case when `facet` is a quosure of a symbol specifically diff --git a/R/position-stack.R b/R/position-stack.R index 2da5c91ef6..6d77269a1f 100644 --- a/R/position-stack.R +++ b/R/position-stack.R @@ -116,14 +116,12 @@ #' #' # Negative values ----------------------------------------------------------- #' -#' df <- tibble::tribble( -#' ~x, ~y, ~grp, -#' "a", 1, "x", -#' "a", 2, "y", -#' "b", 1, "x", -#' "b", 3, "y", -#' "b", -1, "y" +#' df <- data.frame( +#' x = rep(c("a", "b"), 2:3), +#' y = c(1, 2, 1, 3, -1), +#' grp = c("x", "y", "x", "y", "y") #' ) +#' #' ggplot(data = df, aes(x, y, group = grp)) + #' geom_col(aes(fill = grp), position = position_stack(reverse = TRUE)) + #' geom_hline(yintercept = 0) diff --git a/R/summarise-plot.R b/R/summarise-plot.R index bdb7cc7af4..9ab046cb8c 100644 --- a/R/summarise-plot.R +++ b/R/summarise-plot.R @@ -66,7 +66,7 @@ summarise_layout <- function(p) { l <- p$layout layout <- l$layout - layout <- tibble( + layout <- data_frame0( panel = l$layout$PANEL, row = l$layout$ROW, col = l$layout$COL @@ -134,7 +134,7 @@ summarise_layers <- function(p) { # This currently only returns the mappings, but in the future, other # information could be added. - tibble( + data_frame0( mapping = layer_mappings ) } diff --git a/R/utilities.R b/R/utilities.R index 0bddb4b4c6..6a7ca5921d 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -371,10 +371,6 @@ seq_asc <- function(to, from) { } } -# Needed to trigger package loading -#' @importFrom tibble tibble -NULL - # Wrapping vctrs data_frame constructor with no name repair data_frame0 <- function(...) data_frame(..., .name_repair = "minimal") diff --git a/man/position_stack.Rd b/man/position_stack.Rd index 024bfd80a4..646ab3c515 100644 --- a/man/position_stack.Rd +++ b/man/position_stack.Rd @@ -126,14 +126,12 @@ ggplot(series, aes(time, value, group = type)) + # Negative values ----------------------------------------------------------- -df <- tibble::tribble( - ~x, ~y, ~grp, - "a", 1, "x", - "a", 2, "y", - "b", 1, "x", - "b", 3, "y", - "b", -1, "y" +df <- data.frame( + x = rep(c("a", "b"), 2:3), + y = c(1, 2, 1, 3, -1), + grp = c("x", "y", "x", "y", "y") ) + ggplot(data = df, aes(x, y, group = grp)) + geom_col(aes(fill = grp), position = position_stack(reverse = TRUE)) + geom_hline(yintercept = 0) diff --git a/tests/testthat/test-geom-quantile.R b/tests/testthat/test-geom-quantile.R index 742e2850ed..7b6feecb9b 100644 --- a/tests/testthat/test-geom-quantile.R +++ b/tests/testthat/test-geom-quantile.R @@ -8,7 +8,7 @@ test_that("geom_quantile matches quantile regression", { set.seed(6531) x <- rnorm(10) - df <- tibble::tibble( + df <- data_frame0( x = x, y = x^2 + 0.5 * rnorm(10) ) diff --git a/tests/testthat/test-geom-tile.R b/tests/testthat/test-geom-tile.R index 581963a4b2..9034e3c9f7 100644 --- a/tests/testthat/test-geom-tile.R +++ b/tests/testthat/test-geom-tile.R @@ -17,11 +17,10 @@ test_that("accepts width and height aesthetics", { geom_tile(fill = NA, colour = "black", linewidth = 1) out <- get_layer_data(p) - boundary <- as.data.frame(tibble::tribble( - ~xmin, ~xmax, ~ymin, ~ymax, - -1, 1, -1, 1, - -2, 2, -2, 2 - )) + boundary <- data_frame0( + xmin = c(-1, -2), xmax = c(1, 2), + ymin = c(-1, -2), ymax = c(1, 2) + ) expect_equal(out[c("xmin", "xmax", "ymin", "ymax")], boundary) }) diff --git a/tests/testthat/test-scale-discrete.R b/tests/testthat/test-scale-discrete.R index 084511571f..9e8eeaf717 100644 --- a/tests/testthat/test-scale-discrete.R +++ b/tests/testthat/test-scale-discrete.R @@ -1,10 +1,9 @@ # Missing values ---------------------------------------------------------- -df <- tibble::tibble( +df <- data_frame0( x1 = c("a", "b", NA), - x2 = factor(x1), - x3 = addNA(x2), - + x2 = factor(c("a", "b", NA)), + x3 = factor(c("a", "b", NA), levels = c("a", "b", NA), exclude = NULL), y = 1:3 ) diff --git a/tests/testthat/test-sec-axis.R b/tests/testthat/test-sec-axis.R index 02846e9f81..7530c4a70c 100644 --- a/tests/testthat/test-sec-axis.R +++ b/tests/testthat/test-sec-axis.R @@ -171,7 +171,7 @@ test_that("sec axis works with tidy eval", { g } - t <- tibble(x = letters, y = seq(10, 260, 10), z = 1:26) + t <- data_frame0(x = letters, y = seq(10, 260, 10), z = 1:26) p <- f(t, x, y, z) diff --git a/tests/testthat/test-stat-align.R b/tests/testthat/test-stat-align.R index 4c418037b3..457992e747 100644 --- a/tests/testthat/test-stat-align.R +++ b/tests/testthat/test-stat-align.R @@ -1,44 +1,29 @@ test_that("standard alignment works", { - df <- tibble::tribble( - ~g, ~x, ~y, - "a", 1, 2, - "a", 3, 5, - "a", 5, 1, - "b", 2, 3, - "b", 4, 6, - "b", 6, 7 + df <- data_frame0( + g = rep(c("a", "b"), each = 3L), + x = c(1, 3, 5, 2, 4, 6), + y = c(2, 5, 1, 3, 6, 7) ) p <- ggplot(df, aes(x, y, fill = g)) + geom_area(color = "black") expect_doppelganger("align two areas", p) }) test_that("alignment with cliffs works", { - df <- tibble::tribble( - ~g, ~x, ~y, - "a", 1, 2, - "a", 3, 5, - "a", 5, 1, - "b", 2, 3, - "b", 4, 3, - "b", 4, 6, - "b", 6, 7 + df <- data_frame0( + g = rep(c("a", "b"), 3:4), + x = c(1, 3, 5, 2, 4, 4, 6), + y = c(2, 5, 1, 3, 3, 6, 7) ) - p <- ggplot(df, aes(x, y, fill = g)) + geom_area(color = "black") expect_doppelganger("align two areas with cliff", p) }) test_that("alignment with negative and positive values works", { - df <- tibble::tribble( - ~g, ~x, ~y, - "a", 1, 1, - "a", 2, 4, - "a", 3, -4, - "a", 8, 0, - "b", 2, 4, - "b", 6, -4 + df <- data_frame0( + g = rep(c("a", "b"), c(4L, 2L)), + x = c(1, 2, 3, 8, 2, 6), + y = c(1, 4, -4, 0, 4, -4) ) - p <- ggplot(df, aes(x, y, fill = g)) + geom_area(color = "black") expect_doppelganger("align two areas with pos/neg y", p) })