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

NA_character_ is considered as length 2 #699

Closed
bundfussr opened this issue Dec 9, 2022 · 1 comment · Fixed by #701
Closed

NA_character_ is considered as length 2 #699

bundfussr opened this issue Dec 9, 2022 · 1 comment · Fixed by #701
Labels
bug an unexpected problem or unintended behavior

Comments

@bundfussr
Copy link

It seems that NA_character_ is handled as a string of length 2 when writing a SAS transport file with write_xpt(). Consider for example:

t <- data.frame(MYFL = c("Y", NA_character_), id = c(1, 2))
attr(t[["MYFL"]], "width") <- 1
haven::write_xpt(t, "t.xpt", version = 5, name = "t")

It produces

Warning message:
Column `MYFL` contains string values longer than user width 1. Width set to 2 to accommodate. 

and the length of MYFL in the SAS transport file is 2.

Is this intended?

I would expect length 1 and no warning.

@gorcha gorcha added the bug an unexpected problem or unintended behavior label Dec 11, 2022
@gorcha
Copy link
Member

gorcha commented Dec 12, 2022

Hi @bundfussr, thanks for the bug report - this definitely shouldn't come through as length 2, will have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants