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

write_xpt(version=5) silently truncates variable names #771

Open
gowerc opened this issue Mar 3, 2025 · 0 comments
Open

write_xpt(version=5) silently truncates variable names #771

gowerc opened this issue Mar 3, 2025 · 0 comments

Comments

@gowerc
Copy link

gowerc commented Mar 3, 2025

V5 of the xport format only supports variable names up to length 8. Currently write_xpt() allows you to specify names greater than 8 but then silently truncates them. This behaviour seems to be in contradiction to the V8 format implementation which has a length limit of 32 and will throw an error if you exceed it

dat <- data.frame(
    "X1234567_ABC" = c(1,2,3,4,5),
    "X1234567_XYZ" = c(6,7,8,9, 10)
)
haven::write_xpt(dat, "data/longvar.xpt", version = 5)

haven::read_xpt("data/longvar.xpt")

New names:`X1234567` -> `X1234567...1``X1234567` -> `X1234567...2`
# A tibble: 5 × 2
  X1234567...1 X1234567...2
         <dbl>        <dbl>
1            1            6
2            2            7
3            3            8
4            4            9
5            5           10

Example of V8 throwing an error if variable name exceeds 32 bytes

dat <- data.frame(
    "X1111222223333344444555556666677777" = c(1,2,3,4,5)
)
haven::write_xpt(dat, "data/longvar.xpt", version = 8)

Error: Failed to create column `X1111222223333344444555556666677777`: A provided name is too long for the file format.

Ideally v5 should also throw an error if variable names exceed the length limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant