Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated features from ggplot2 #141

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Suggests:
tidyr (>= 0.8.1),
vctrs,
withr
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ S3method(as_bench_bytes,numeric)
S3method(as_bench_time,bench_time)
S3method(as_bench_time,default)
S3method(as_bench_time,numeric)
S3method(dplyr::filter,bench_mark)
S3method(dplyr::group_by,bench_mark)
S3method(format,bench_bytes)
S3method(format,bench_expr)
S3method(format,bench_time)
S3method(ggplot2::autoplot,bench_mark)
S3method(ggplot2::scale_type,bench_bytes)
S3method(ggplot2::scale_type,bench_expr)
S3method(ggplot2::scale_type,bench_time)
S3method(knitr::knit_print,bench_mark)
S3method(max,bench_bytes)
S3method(max,bench_time)
S3method(mean,bench_time)
Expand All @@ -37,9 +44,12 @@ S3method(rbind,bench_mark)
S3method(sum,bench_bytes)
S3method(sum,bench_time)
S3method(summary,bench_mark)
S3method(tidyr::unnest,bench_mark)
S3method(type_sum,bench_bytes)
S3method(type_sum,bench_expr)
S3method(type_sum,bench_time)
S3method(vctrs::vec_proxy,bench_expr)
S3method(vctrs::vec_restore,bench_expr)
export(as_bench_bytes)
export(as_bench_mark)
export(as_bench_time)
Expand Down Expand Up @@ -67,4 +77,5 @@ export(workout_expressions)
importFrom(methods,setOldClass)
importFrom(pillar,pillar_shaft)
importFrom(pillar,type_sum)
importFrom(rlang,.data)
useDynLib(bench, .registration = TRUE)
23 changes: 11 additions & 12 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param ... Additional arguments passed to the plotting geom.
#' @details This function requires some optional dependencies. [ggplot2][ggplot2::ggplot2-package],
#' [tidyr][tidyr::tidyr-package], and depending on the plot type
#' [ggbeeswarm][ggbeeswarm::ggbeeswarm], [ggridges][ggridges::ggridges].
#' [ggbeeswarm][ggbeeswarm::ggbeeswarm], [ggridges][ggridges::ggridges-package].
#'
#' For `type` of `beeswarm` and `jitter` the points are colored by the highest
#' level garbage collection performed during each iteration.
Expand Down Expand Up @@ -45,17 +45,16 @@
#' autoplot("violin")
#' }
#' }
#' @exportS3Method ggplot2::autoplot
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 +72,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
1 change: 1 addition & 0 deletions R/bytes.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ bench_bytes_trans <- function(base = 2) {
scales::log_breaks(base = base), domain = c(1e-100, Inf))
}

#' @exportS3Method ggplot2::scale_type
scale_type.bench_bytes <- function(x) "bench_bytes"

#' Position scales for bench_time data
Expand Down
5 changes: 3 additions & 2 deletions R/expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ type_sum.bench_expr <- function(x) {
new_bench_expr(new_x)
}

# @export
#' @exportS3Method vctrs::vec_proxy
vec_proxy.bench_expr <- function(x, ...) {
desc <- attr(x, "description")
attributes(x) <- NULL
out <- list(x = x, desc = desc)
vctrs::new_data_frame(out, n = length(x))
}

# @export
#' @exportS3Method vctrs::vec_restore
vec_restore.bench_expr <- function(x, to, ...) {
new_bench_expr(x$x, x$desc)
}
Expand All @@ -55,6 +55,7 @@ pillar_shaft.bench_expr <- function(x, ...) {
pillar_shaft(as.character(x), ...)
}

#' @exportS3Method ggplot2::scale_type
scale_type.bench_expr <- function(x) {
"bench_expr"
}
Expand Down
187 changes: 0 additions & 187 deletions R/import-standalone-s3-register.R

This file was deleted.

4 changes: 4 additions & 0 deletions R/mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ parse_allocations <- function(filename) {
#'
#' @param options A list of knitr chunk options set in the currently evaluated
#' chunk.
#' @exportS3Method knitr::knit_print
knit_print.bench_mark <- function(x, ..., options) {
if (!isTRUE(options$bench.all_columns)) {
x <- x[!colnames(x) %in% data_cols]
Expand All @@ -339,6 +340,7 @@ parse_gc <- function(x) {

utils::globalVariables(c("time", "gc"))

#' @exportS3Method tidyr::unnest
unnest.bench_mark <- function(data, ...) {
if (inherits(data[["expression"]], "bench_expr")) {
data[["expression"]] <- as.character(data[["expression"]])
Expand Down Expand Up @@ -376,12 +378,14 @@ rbind.bench_mark <- function(..., deparse.level = 1) {
res
}

#' @exportS3Method dplyr::filter
filter.bench_mark <- function(.data, ...) {
dots <- rlang::quos(...)
idx <- Reduce(`&`, lapply(dots, rlang::eval_tidy, data = .data))
.data[idx, ]
}

#' @exportS3Method dplyr::group_by
group_by.bench_mark <- function(.data, ...) {
bench_mark(NextMethod())
}
1 change: 1 addition & 0 deletions R/time.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ bench_time_trans <- function(base = 10) {
scales::log_breaks(base = base), domain = c(1e-100, Inf))
}

#' @exportS3Method ggplot2::scale_type
scale_type.bench_time <- function(x) "bench_time"

#' Position scales for bench_time data
Expand Down
17 changes: 0 additions & 17 deletions R/zzz.R

This file was deleted.

Loading
Loading