diff --git a/NAMESPACE b/NAMESPACE index 4ae0918..542a24d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/autoplot.R b/R/autoplot.R index cca9a6b..a0290cf 100644 --- a/R/autoplot.R +++ b/R/autoplot.R @@ -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 @@ -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()) diff --git a/R/bench-package.R b/R/bench-package.R index 047dd63..44375d1 100644 --- a/R/bench-package.R +++ b/R/bench-package.R @@ -2,6 +2,7 @@ #' @importFrom methods setOldClass #' @importFrom pillar pillar_shaft #' @importFrom pillar type_sum +#' @importFrom rlang .data ## usethis namespace: end NULL diff --git a/tests/testthat/test-autoplot.R b/tests/testthat/test-autoplot.R new file mode 100644 index 0000000..6dc2ca3 --- /dev/null +++ b/tests/testthat/test-autoplot.R @@ -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") +})