Skip to content

Commit

Permalink
Use NA_real_ for na.value in continous scales
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jul 26, 2012
1 parent 19c8103 commit 0999e2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/bounds.r
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions R/scale-continuous.r
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0999e2a

Please sign in to comment.