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.
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 itExample of V8 throwing an error if variable name exceeds 32 bytes
Ideally v5 should also throw an error if variable names exceed the length limit.