Skip to content

Commit

Permalink
Remove deprecated feature from ggplot2 + add minimal test to help for…
Browse files Browse the repository at this point in the history
…see deprecation warning.
  • Loading branch information
olivroy committed Feb 21, 2024
1 parent 129a852 commit e75d9d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ export(workout_expressions)
importFrom(methods,setOldClass)
importFrom(pillar,pillar_shaft)
importFrom(pillar,type_sum)
importFrom(rlang,.data)
useDynLib(bench, .registration = TRUE)
18 changes: 8 additions & 10 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@
autoplot.bench_mark <- function(object,
type = c("beeswarm", "jitter", "ridge", "boxplot", "violin"),...) {

if (!(requireNamespace("ggplot2") && requireNamespace("tidyr"))) {
stop("`ggplot2` and `tidyr` must be installed to use `autoplot`.", call. = FALSE)
}
rlang::check_installed(c("ggplot2", "tidyr"), "for `autoplot()`.")

type <- match.arg(type)

if (type == "beeswarm" && !requireNamespace("ggbeeswarm", quietly = TRUE)) {
stop("`ggbeeswarm` must be installed to use `type = \"beeswarm\"` option.", call. = FALSE)
if (type == "beeswarm") {
rlang::check_installed("ggbeeswarm", "to use `type = \"beeswarm\" option.")
}

# Just convert bench_expr to characters
Expand All @@ -73,26 +71,26 @@ autoplot.bench_mark <- function(object,

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

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions R/bench-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' @importFrom methods setOldClass
#' @importFrom pillar pillar_shaft
#' @importFrom pillar type_sum
#' @importFrom rlang .data
## usethis namespace: end
NULL

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-autoplot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test_that("autoplot works", {
skip_on_cran()
skip_if_not_installed("ggplot2")
skip_if_not_installed("tidyr")
skip_if_not_installed("ggbeeswarm")
y <- mark(x = 1:1000)
expect_s3_class(ggplot2::autoplot(y), "ggplot")
expect_s3_class(plot(y), "ggplot")
})

0 comments on commit e75d9d0

Please sign in to comment.