Am I the only one experiencing problems with R's haven package?

1.5k views Asked by At

I want to open a stata file in R, via haven::read_dta(). I'have created my script a few weeks ago and it all worked well until now: suddenly, when I try loading the data my session crashes ("R Session Aborted"). A colleague of mine is having the same problem.

I' ve tried many things: choosing the correct working directory via setwd(), choosing the file via choose.files(), entering the filepath with "/", "//" and "\" but nothing seems to work.

They way it worked until now was:

install.packages("haven")
library(haven)

my_data <- read_dta("my_path_structure\\file_name.dta")

Anyone having the same problem?

EDIT: Problem should be fixed soon. For more information see here.

3

There are 3 answers

8
AudioBubble On BEST ANSWER

Issue

On the 14th, Haven updated to 2.4.0 where they internally upgraded to ReadStat 1.1.5. which handles the import of .dta files. There doesn't appear to be any codebreaking updates in ReadStat 1.1.5..

I was able to reproduce your abort error in R Studio which gives no information. I went directly to the R Console and it gives me the following segmentation error after running the same code:

*** caught segfault ***
address 0x0, cause 'invalid permissions'

Given that this was not an issue with the previous build of Haven, I would make a bug report with the developer.

Temporary Solution

I was able to get around this issue by using the readstata13 package instead. Here is an example,

install.packages("readstata13")
library(readstata13)
my_data <- read.dta13("my_path_structure/file_name.dta")
1
leftsinkhandle On

I came across this same issue. My solution was to install Haven 2.3.1.

packageUrl <- "https://cran.r-project.org/src/contrib/Archive/haven/haven_2.3.1.tar.gz"

# only needed if haven is attached
detach("package:haven", unload = TRUE)

install.packages(packageUrl, repos=NULL, type="source")
0
nicholas On

As of 7/27/2021, this problem is fixed in the development version of Haven. Run devtools::install_github("tidyverse/haven").