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 DFrame
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 2023-09-20.

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 

## DFrame ====
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