The read_xpt() function cannot properly handle a SAS transport file (XPORT format) that contains multiple SAS datasets. Instead of reading all of them into separate data frames (or tibbles) the way that read.xport() does it mistakenly reads the entire file as part of the first dataset, generating gibberish observations.
The v5.xpt file in this ZIP file has two datasets, MISSING and CLASS.
v5.xpt.zip
x <- "~/Documents/Rprojects/v5.xpt"
library(foreign)
y <- read.xport(x)
library(haven)
z <- read_xpt(x)
The read.xport() function from foreign properly reads the two datasets making y$MISSING as a data frame with 2 variables and 31 observations. And y$CLASS as a data frame with 5 variable and 19 observation.
But the read_xpt() function makes a single tibble with two variables and 239 observations. The first 31 are fine, but the rest are gibberish.
The read_xpt() function cannot properly handle a SAS transport file (XPORT format) that contains multiple SAS datasets. Instead of reading all of them into separate data frames (or tibbles) the way that read.xport() does it mistakenly reads the entire file as part of the first dataset, generating gibberish observations.
The v5.xpt file in this ZIP file has two datasets, MISSING and CLASS.
v5.xpt.zip
The read.xport() function from foreign properly reads the two datasets making y$MISSING as a data frame with 2 variables and 31 observations. And y$CLASS as a data frame with 5 variable and 19 observation.
But the read_xpt() function makes a single tibble with two variables and 239 observations. The first 31 are fine, but the rest are gibberish.