Skip to content

NA_character_ is considered as length 2 #699

Closed

Description

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.

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

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