Skip to contents

Standardize empty strings (""), character NAs ("NA"), and NULL values inside a character vector to NA_character_. Other atomic data types are returned unmodified.

Usage

sanitizeNA(object, ...)

# S4 method for DataFrame
sanitizeNA(object)

# S4 method for atomic
sanitizeNA(object)

# S4 method for character
sanitizeNA(object)

# S4 method for data.frame
sanitizeNA(object)

# S4 method for factor
sanitizeNA(object)

Arguments

object

Object.

...

Additional arguments.

Value

Modified object. Sanitized to contain proper NA values.

Note

Updated 2021-02-11.

Examples

## character ====
from <- as.character(c(1L, "x", "", "NA", "NULL"))
print(from)
#> [1] "1"    "x"    ""     "NA"   "NULL"
to <- sanitizeNA(from)
print(to)
#> [1] "1" "x" NA  NA  NA 

## DataFrame ====
from <- S4Vectors::DataFrame(
    "a" = c("foo", ""),
    "b" = c(NA, "bar"),
    row.names = c("c", "d")
)
print(from)
#> DataFrame with 2 rows and 2 columns
#>             a           b
#>   <character> <character>
#> c         foo          NA
#> d                     bar
to <- sanitizeNA(from)
print(to)
#> DataFrame with 2 rows and 2 columns
#>             a           b
#>   <character> <character>
#> c         foo          NA
#> d          NA         bar