haven v1.0.0


Monthly downloads



by Hadley Wickham

Import and Export 'SPSS', 'Stata' and 'SAS' Files

Import foreign statistical formats into R via the embedded 'ReadStat' C library (https://github.com/WizardMac/ReadStat).



Travis-CI Build Status Coverage Status CRAN_Status_Badge

Haven allows you to load foreign data formats (SAS, SPSS and Stata) in to R by wrapping the fantastic ReadStat C library written by Evan Miller. Haven offers similar functionality to the base foreign package but:

  • It reads SPSS files (.dta and .por), reads Stata 13 and 14 files (foreign only works up to Stata 12), and SAS's proprietary binary format (SAS7BDAT + SAS7BCAT). It does not support many of the now more exotic formats supported by foreign.

  • Can also write SPSS, Stata, and SAS files.

  • Date times are converted to corresponding R classes and labelled vectors are returned as a new labelled class. You can easily coerce to factors or replace labelled values with missings as appropriate. All functions return tibbles.

  • Uses underscores instead of dots ;)

Haven is still a work in progress so please file an issue if it fails to correctly load a file that you're interested in.


# Install the released version from CRAN:

# Install the cutting edge development version from GitHub:
# install.packages("devtools")


  • SAS: read_sas("path/to/file")
  • SPSS: read_sav("path/to/file")
  • Stata: read_dta("path/to/file")

Functions in haven

Name Description
zap_formats Remove format attributes
read_spss Read SPSS (SAV & POR) files. Write SAV files.
print_labels Print the labels of a labelled vector
read_dta Read and write Stata DTA files.
tagged_na "Tagged" missing values
labelled_spss Labelled vectors for SPSS
read_sas Read and write SAS files.
zap_empty Convert empty strings into missing values.
labelled Create a labelled vector.
as_factor Convert input to a factor.
zap_missing Zap special missings to regular R missings
zap_labels Zap labels
No Results!

Last month downloads


License MIT + file LICENSE
LinkingTo Rcpp, BH
LazyData true
URL https://github.com/hadley/haven, https://github.com/WizardMac/ReadStat
BugReports https://github.com/hadley/haven/issues
VignetteBuilder knitr
SystemRequirements GNU make
RoxygenNote 5.0.1
Encoding UTF-8
NeedsCompilation yes
Packaged 2016-09-23 20:35:30 UTC; hadley
Repository CRAN
Date/Publication 2016-09-23 22:44:41

Include our badge in your README