Skip to content

Commit

Permalink
Fix configuration of breaks when using recent scales package.
Browse files Browse the repository at this point in the history
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 r-lib/scales#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.
  • Loading branch information
plietar committed Feb 19, 2024
1 parent 8d4ab5e commit 4337cab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions R/bytes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions R/time.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,19 @@ 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)
)
)
}

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"
Expand Down

0 comments on commit 4337cab

Please sign in to comment.