Haven enables R to read and write various data formats used by other statistical packages by wrapping the fantastic ReadStat C library written by Evan Miller. Haven is part of the tidyverse. Currently it supports:
.sas7bcat files and
read_xpt() reads SAS transport files (version 5 and version 8).
.sav files and
read_por() reads the older
.dta files (up to version 14).
.dta files (versions 8-14).
The output objects:
Are tibbles, which have a better print method for very long and very wide files.
Translate value labels into a new
labelled() class, which preserves the original semantics and can easily be coerced to factors with
as_factor(). Special missing values are preserved. See
vignette("semantics") for more details.
Dates and times are converted to R date/time classes. Character vectors are not converted to factors.
# The easiest way to get haven is to install the whole tidyverse: install.packages("tidyverse") # Alternatively, install just haven: install.packages("haven") # Or the the development version from GitHub: # install.packages("devtools") devtools::install_github("tidyverse/haven")
library(haven) # SAS read_sas("mtcars.sas7bdat") write_sas(mtcars, "mtcars.sas7bdat") # SPSS read_sav("mtcars.sav") write_sav(mtcars, "mtcars.sav") # Stata read_dta("mtcars.dta") write_dta(mtcars, "mtcars.dta")