Overview

Haven allows is designed to write and read data formats used by other statistical packages by wrapping the fantastic ReadStat C library written by Evan Miller. Currently it supports:

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 preserve the original semantics and can easily coerced to factors with as_factor(). Special missing values are preserved. See vignette("semantics") for more details.

  • Date/times are converted to R date/time classes. Character vectors are not converted to factors.

Installation

# 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")

Usage

library(haven)

# SAS
write_sas(mtcars, "mtcars.sas7bdat")
read_sas("mtcars.sas7bdat")

# Stata
write_dta(mtcars, "mtcars.dta")
read_dta("mtcars.dta")

# SPSS
write_sav(mtcars, "mtcars.sav")
read_sav("mtcars.sav")