From fcc6e3fd959784a5594a9cb490fc01553cca4c3c Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:09:13 +0100 Subject: [PATCH 1/5] Coerce `new` to numeric --- R/scale-continuous.r | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/scale-continuous.r b/R/scale-continuous.r index 5ba6eb1a..b2981f00 100644 --- a/R/scale-continuous.r +++ b/R/scale-continuous.r @@ -46,7 +46,10 @@ train_continuous <- function(new, existing = NULL) { stop("Discrete value supplied to continuous scale", call. = FALSE) } - suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE)) + # Needs casting to numeric because some `new` vectors can misbehave when + # combined with a NULL `existing` (#369) + suppressWarnings(range(existing, as.numeric(new), + na.rm = TRUE, finite = TRUE)) } # Map values for a continuous palette. From d40a2e8d732ca5876f66f6bb430b3eff5c81c2b9 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:09:46 +0100 Subject: [PATCH 2/5] Add test for integer64 training --- tests/testthat/test-scale-continuous.r | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-scale-continuous.r b/tests/testthat/test-scale-continuous.r index fd81e4f2..8c8e3074 100644 --- a/tests/testthat/test-scale-continuous.r +++ b/tests/testthat/test-scale-continuous.r @@ -27,3 +27,12 @@ test_that("train_continuous with new=NULL maintains existing range.", { c(1, 5) ) }) + +test_that("train_continuous works with integer64", { + skip_if_not_installed("bit64") + new <- bit64::as.integer64(1:10) + expect_identical( + train_continuous(new), + c(1, 10) + ) +}) From 21bf45ef30bca7283781bfd26b5ed38114b238d4 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:09:55 +0100 Subject: [PATCH 3/5] Add NEWS bullet --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 71228d4b..1e3b17eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # scales (development version) +* `train_continuous()` coerces `new` to numeric before calculating range + (@teunbrand, #369). + # scales 1.2.1 * Re-document to fix HTML issues in `.Rd`. From fd2c2f9c2635cccf214cc3910c3eeeb11494bec1 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 12 Dec 2022 20:45:41 +0100 Subject: [PATCH 4/5] Update 'domain' documentation --- R/trans.r | 3 ++- man/trans_new.Rd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/trans.r b/R/trans.r index 93849a3b..a4f0b662 100644 --- a/R/trans.r +++ b/R/trans.r @@ -18,7 +18,8 @@ #' @param format default format for this transformation. The format is applied #' to breaks generated to the raw data. #' @param domain domain, as numeric vector of length 2, over which -#' transformation is valued +#' transformation is valued. The function in the `transform` argument is +#' expected to be able to transform the `domain` argument. #' @seealso \Sexpr[results=rd,stage=build]{scales:::seealso_trans()} #' @export #' @keywords internal diff --git a/man/trans_new.Rd b/man/trans_new.Rd index 00d59b0c..eb42efd4 100644 --- a/man/trans_new.Rd +++ b/man/trans_new.Rd @@ -39,7 +39,8 @@ function is applied to the raw data.} to breaks generated to the raw data.} \item{domain}{domain, as numeric vector of length 2, over which -transformation is valued} +transformation is valued. The function in the \code{transform} argument is +expected to be able to transform the \code{domain} argument.} } \description{ A transformation encapsulates a transformation and its inverse, as well From 66da3bb0f92327438bf93586d6cc71daad18b068 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 12 Dec 2022 20:47:21 +0100 Subject: [PATCH 5/5] Revert "Update 'domain' documentation" This reverts commit fd2c2f9c2635cccf214cc3910c3eeeb11494bec1. --- R/trans.r | 3 +-- man/trans_new.Rd | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/R/trans.r b/R/trans.r index a4f0b662..93849a3b 100644 --- a/R/trans.r +++ b/R/trans.r @@ -18,8 +18,7 @@ #' @param format default format for this transformation. The format is applied #' to breaks generated to the raw data. #' @param domain domain, as numeric vector of length 2, over which -#' transformation is valued. The function in the `transform` argument is -#' expected to be able to transform the `domain` argument. +#' transformation is valued #' @seealso \Sexpr[results=rd,stage=build]{scales:::seealso_trans()} #' @export #' @keywords internal diff --git a/man/trans_new.Rd b/man/trans_new.Rd index eb42efd4..00d59b0c 100644 --- a/man/trans_new.Rd +++ b/man/trans_new.Rd @@ -39,8 +39,7 @@ function is applied to the raw data.} to breaks generated to the raw data.} \item{domain}{domain, as numeric vector of length 2, over which -transformation is valued. The function in the \code{transform} argument is -expected to be able to transform the \code{domain} argument.} +transformation is valued} } \description{ A transformation encapsulates a transformation and its inverse, as well