Skip to content

max_level_lengths can't deal with missings in levels #301

Closed
@rubenarslan

Description

@rubenarslan

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions