Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max_level_lengths can't deal with missings in levels #301

Closed
rubenarslan opened this issue Jul 27, 2017 · 1 comment
Closed

max_level_lengths can't deal with missings in levels #301

rubenarslan opened this issue Jul 27, 2017 · 1 comment
Labels

Comments

@rubenarslan
Copy link
Contributor

@rubenarslan rubenarslan commented Jul 27, 2017

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

@hadley hadley added the bug label Jan 7, 2018
@hadley hadley closed this in 8c3dd6b Jan 16, 2018
@lock
Copy link

@lock lock bot commented Jul 15, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

Loading

@lock lock bot locked and limited conversation to collaborators Jul 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants