Skip to content

TobiasFellinger/haven

This branch is up to date with tidyverse/haven:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d83f406 · Oct 10, 2024
Oct 31, 2023
Oct 10, 2024
Jun 10, 2016
Oct 31, 2023
Oct 31, 2023
Feb 27, 2023
Nov 29, 2023
Feb 25, 2023
Feb 25, 2023
Apr 15, 2022
Jan 5, 2019
Feb 7, 2022
Nov 30, 2023
Oct 31, 2023
Oct 31, 2023
Dec 14, 2022
Nov 30, 2023
Jan 31, 2023
Jan 31, 2023
Apr 18, 2022
Apr 7, 2022
Apr 20, 2020
Feb 7, 2022
Feb 7, 2022
Jun 29, 2023
Aug 19, 2022

Repository files navigation

haven

CRAN status R-CMD-check Codecov test coverage

Overview

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:

  • SAS: read_sas() reads .sas7bdat + .sas7bcat files and read_xpt() reads SAS transport files (versions 5 and 8). write_xpt() writes SAS transport files (versions 5 and 8).

  • SPSS: read_sav() reads .sav files and read_por() reads the older .por files. write_sav() writes .sav files.

  • Stata: read_dta() reads .dta files (up to version 15). write_dta() writes .dta files (versions 8-15).

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.

Installation

# The easiest way to get haven is to install the whole tidyverse:
install.packages("tidyverse")

# Alternatively, install just haven:
install.packages("haven")

Usage

library(haven)

# SAS
read_sas("mtcars.sas7bdat")
write_xpt(mtcars, "mtcars.xpt")

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

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

Related work

  • foreign reads from SAS XPORT, SPSS, and Stata (up to version 12) files.

  • readstat13 reads from and writes to all Stata file format versions.

  • sas7bdat reads from SAS7BDAT files.

Code of Conduct

Please note that the haven project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

Read SPSS, Stata and SAS files from R

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 79.8%
  • R 10.5%
  • Ragel 4.9%
  • C++ 4.8%