Closed
Description
If there is an NA in a factor level, haven will fail to write because of the following error.
x = data.frame(x = factor(c(1, 2, 3, NA), exclude = NULL))
haven::write_sav(x, path = tempfile())
#> Error in if (any(bad_lengths)) {: missing value where TRUE/FALSE needed
I this can easily be fixed by changing
max(nchar(levels(x)))
to
max(nchar(levels(x)), na.rm = TRUE)
in haven:::max_level_lengths
Activity