Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

revalue: accept NULL input

  • Loading branch information...
commit bea57ace860b7676a2c37b3e0b9f212edbe3775e 1 parent 8ce8e27
@wch wch authored
Showing with 5 additions and 2 deletions.
  1. +1 −1  R/helper-revalue.r
  2. +4 −1 inst/tests/test-revalue.r
View
2  R/helper-revalue.r
@@ -24,7 +24,7 @@
#' y <- factor(c("a", "b", "c", "a"))
#' revalue(y, c(a = "A", c = "C"))
revalue <- function(x, replace = NULL, warn_missing = TRUE) {
- if (!is.factor(x) && !is.character(x)) {
+ if (!is.null(x) && !is.factor(x) && !is.character(x)) {
stop("x is not a factor or a character vector.")
}
View
5 inst/tests/test-revalue.r
@@ -111,7 +111,10 @@ test_that("revalue and mapvalues only accept atomic vectors", {
expect_error(mapvalues(list(A=3), 3, 30))
})
-test_that("revalue and mapvalues accept empty vectors", {
+test_that("revalue and mapvalues accept empty vectors and NULL", {
expect_identical(revalue(character(0), c("3"=30), warn_missing=FALSE), character(0))
expect_identical(mapvalues(character(0), 3, 30, warn_missing=FALSE), character(0))
+
+ expect_identical(revalue(NULL, c("3"=30), warn_missing=FALSE), NULL)
+ expect_identical(mapvalues(NULL, 3, 30, warn_missing=FALSE), NULL)
})

0 comments on commit bea57ac

Please sign in to comment.
Something went wrong with that request. Please try again.