diff --git a/R/bounds.r b/R/bounds.r index dc4ec157..29e5b77d 100644 --- a/R/bounds.r +++ b/R/bounds.r @@ -59,8 +59,10 @@ rescale_none <- function(x, ...) { censor <- function(x, range = c(0, 1), only.finite = TRUE) { force(range) finite <- if (only.finite) is.finite(x) else TRUE - x[finite & x < range[1]] <- NA - x[finite & x > range[2]] <- NA + # Assign NA - this makes sure that, even if all elements are + # replaced with NA, it stays numeric (and isn't changed to logical) + x[finite & x < range[1]] <- NA_real_ + x[finite & x > range[2]] <- NA_real_ x } diff --git a/R/scale-continuous.r b/R/scale-continuous.r index 4e070b8e..70d39cee 100644 --- a/R/scale-continuous.r +++ b/R/scale-continuous.r @@ -20,7 +20,7 @@ #' with(mtcars, plot(disp, mpg, cex = cscale(hp, area_pal()))) #' with(mtcars, plot(disp, mpg, pch = 20, cex = 5, #' col = cscale(hp, seq_gradient_pal("grey80", "black")))) -cscale <- function(x, palette, na.value = NA, trans = identity_trans()) { +cscale <- function(x, palette, na.value = NA_real_, trans = identity_trans()) { stopifnot(is.trans(trans)) x <- trans$trans(x) @@ -41,7 +41,7 @@ train_continuous <- function(new, existing = NULL) { # # @param oob out of bounds behaviour. Defaults to \code{\link{censor}} # which turns oob values into missing values. -map_continuous <- function(palette, x, limits, na.value = NA, oob = censor) { +map_continuous <- function(palette, x, limits, na.value = NA_real_, oob = censor) { x <- oob(rescale(x, from = limits)) pal <- palette(x) ifelse(!is.na(x), pal, na.value)