From 4337cab72c290c4cebbb863ea22575cba21940d9 Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Mon, 19 Feb 2024 16:13:25 +0000 Subject: [PATCH] Fix configuration of breaks when using recent scales package. The latest release of the scales package has added a pair of optional arguments, `d_transform` and `d_inverse`, in the middle of the parameter list for `trans_new` (see https://github.com/r-lib/scales/pull/341). As a consequence, this has shifted the position of the `breaks` parameter from 4th to 6th. Because the `bench_time_trans` and `bench_bytes_trans` functions from this package were passing in the breaks object positionally, this change in the scales package means that the breaks object is now matched with the new `d_transform` formal parameter and it ends up being ignored. This commit changes the arguments to `trans_new` from being positional to being named, which should be more robust to future changes to the function. --- R/bytes.R | 10 ++++++---- R/time.R | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/R/bytes.R b/R/bytes.R index 9e59dc2..9f2f18e 100644 --- a/R/bytes.R +++ b/R/bytes.R @@ -169,16 +169,18 @@ type_sum.bench_bytes <- function(x) { bench_bytes_trans <- function(base = 2) { if (is.null(base)) { return( - scales::trans_new("bch:byt", as.numeric, as_bench_bytes, - scales::pretty_breaks(), domain = c(1e-100, Inf) + scales::trans_new("bch:byt", transform = as.numeric, + inverse = as_bench_bytes, breaks = scales::pretty_breaks(), + domain = c(1e-100, Inf) ) ) } trans <- function(x) log(as.numeric(x), base) inv <- function(x) as_bench_bytes(base ^ as.numeric(x)) - scales::trans_new(paste0("bch:byt-", format(base)), trans, inv, - scales::log_breaks(base = base), domain = c(1e-100, Inf)) + scales::trans_new(paste0("bch:byt-", format(base)), transform = trans, + inverse = inv, breaks = scales::log_breaks(base = base), + domain = c(1e-100, Inf)) } scale_type.bench_bytes <- function(x) "bench_bytes" diff --git a/R/time.R b/R/time.R index 9159edb..3a681e1 100644 --- a/R/time.R +++ b/R/time.R @@ -209,8 +209,9 @@ type_sum.bench_time <- function(x) { bench_time_trans <- function(base = 10) { if (is.null(base)) { return( - scales::trans_new("bch:tm", as.numeric, as_bench_time, - scales::pretty_breaks(), domain = c(1e-100, Inf) + scales::trans_new("bch:tm", transform = as.numeric, + inverse = as_bench_time, breaks = scales::pretty_breaks(), + domain = c(1e-100, Inf) ) ) } @@ -218,8 +219,9 @@ bench_time_trans <- function(base = 10) { trans <- function(x) log(as.numeric(x), base) inv <- function(x) as_bench_time(base ^ as.numeric(x)) - scales::trans_new(paste0("bch:tm-", format(base)), trans, inv, - scales::log_breaks(base = base), domain = c(1e-100, Inf)) + scales::trans_new(paste0("bch:tm-", format(base)), transform = trans, + inverse = inv, breaks = scales::log_breaks(base = base), + domain = c(1e-100, Inf)) } scale_type.bench_time <- function(x) "bench_time"