Skip to content

Commit

Permalink
Rf_isNA is FALSE for NaN.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jan 25, 2016
1 parent 7fc502c commit ae775b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
@@ -1,6 +1,9 @@
Version 0.3.0.9000
------------------------------------------------------------------------------

* NaN is correctly recognised as a missing value by the gradient palettes
(ggplot2#1482).

Version 0.3.0
------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/colors.cpp
Expand Up @@ -143,7 +143,7 @@ StringVector doColorRampSerial(NumericMatrix colors, NumericVector x, bool alpha
StringVector result(x.length());
for (R_len_t i = 0; i < x.length(); i++) {
double xval = x[i];
if (xval < 0 || xval > 1 || R_IsNA(xval)) {
if (xval < 0 || xval > 1 || !R_finite(xval)) {
// Illegal or NA value for this x value.
result[i] = NA_STRING;
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-colour-ramp.R
@@ -0,0 +1,10 @@
context("Colour ramp")

test_that("Special values yield NAs", {
pal <- seq_gradient_pal()

expect_equal(pal(NA), NA_character_)
expect_equal(pal(NaN), NA_character_)
expect_equal(pal(Inf), NA_character_)
expect_equal(pal(-Inf), NA_character_)
})

0 comments on commit ae775b2

Please sign in to comment.