Skip to content

Commit

Permalink
Remove usage of coord_flip() (#147)
Browse files Browse the repository at this point in the history
* Require tidyr 1.0.0 everywhere

* coord_flip() is superseded since ggplot2 3.3
  • Loading branch information
olivroy authored Jan 16, 2025
1 parent a96f013 commit 83c1914
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
28 changes: 10 additions & 18 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ autoplot.bench_mark <- function(
type = c("beeswarm", "jitter", "ridge", "boxplot", "violin"),
...
) {
rlang::check_installed(c("ggplot2", "tidyr"), "for `autoplot()`.")
rlang::check_installed(c("ggplot2", "tidyr (>= 1.0.0)"), "for `autoplot()`.")

type <- match.arg(type)

Expand All @@ -64,38 +64,30 @@ autoplot.bench_mark <- function(
object$expression <- as.character(object$expression)
}

if (tidyr_new_interface()) {
res <- tidyr::unnest(object, c(time, gc))
} else {
res <- tidyr::unnest(object)
}
res <- tidyr::unnest(object, c(time, gc))
p <- ggplot2::ggplot(res)

switch(
type,
beeswarm = p <- p +
ggplot2::aes(.data$expression, .data$time, color = .data$gc) +
ggbeeswarm::geom_quasirandom(...) +
ggplot2::coord_flip(),
ggplot2::aes(.data$time, .data$expression, color = .data$gc) +
ggbeeswarm::geom_quasirandom(..., orientation = "y"),

jitter = p <- p +
ggplot2::aes(.data$expression, .data$time, color = .data$gc) +
ggplot2::geom_jitter(...) +
ggplot2::coord_flip(),
ggplot2::aes(.data$time, .data$expression, color = .data$gc) +
ggplot2::geom_jitter(...),

ridge = p <- p +
ggplot2::aes(.data$time, .data$expression) +
ggridges::geom_density_ridges(...),

boxplot = p <- p +
ggplot2::aes(.data$expression, .data$time) +
ggplot2::geom_boxplot(...) +
ggplot2::coord_flip(),
ggplot2::aes(.data$time, .data$expression) +
ggplot2::geom_boxplot(...),

violin = p <- p +
ggplot2::aes(.data$expression, .data$time) +
ggplot2::geom_violin(...) +
ggplot2::coord_flip()
ggplot2::aes(.data$time, .data$expression) +
ggplot2::geom_violin(...)
)

parameters <- setdiff(
Expand Down
8 changes: 1 addition & 7 deletions R/mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,7 @@ unnest.bench_mark <- function(data, ...) {

# suppressWarnings to avoid 'elements may not preserve their attributes'
# warnings from dplyr::collapse
if (tidyr_new_interface()) {
data <- suppressWarnings(NextMethod(.Generic, data, ...))
} else {
data <- suppressWarnings(
NextMethod(.Generic, data, time, gc, .drop = FALSE)
)
}
data <- suppressWarnings(NextMethod(.Generic, data, ...))

# Add bench_time class back to the time column
data$time <- as_bench_time(data$time)
Expand Down
5 changes: 0 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ lengths <- function(x, use.names = TRUE) {
viapply(x, length, USE.NAMES = use.names)
}

# check if the new interface is being used
tidyr_new_interface <- function() {
utils::packageVersion("tidyr") > "0.8.99"
}

dots <- function(...) {
dots <- as.list(substitute(...()))

Expand Down
8 changes: 2 additions & 6 deletions tests/testthat/test-mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,9 @@ describe("summary.bench_mark", {

describe("unnest.bench_mark", {
it("does not contain result or memory columns", {
skip_if_not_installed("tidyr")
skip_if_not_installed("tidyr", "1.0.0")
bnch <- mark(1 + 1, 2 + 0)
if (tidyr_new_interface()) {
res <- tidyr::unnest(bnch, c(time, gc))
} else {
res <- tidyr::unnest(bnch)
}
res <- tidyr::unnest(bnch, c(time, gc))

gc_cols <- colnames(bnch$gc[[1]])

Expand Down

0 comments on commit 83c1914

Please sign in to comment.