4

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.

micsky
  • 113
  • 12

3 Answers3

3

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")
  • forward-slash `/` should work as a path separator in R on any OS ... (`\\` *only* works on Windows) – Ben Bolker Apr 27 '21 at 20:50
  • Thanks @BenBolker, I've gone ahead and edited my answer. –  Apr 27 '21 at 20:50
  • Thanks @JesseKaczmarski. May I ask you how you've produced this feedback from the console? Because if I enter the code directly there the window shuts down immediately. – micsky Apr 27 '21 at 21:13
  • 1
    Yes! I'm sorry I wasn't more specific. Instead of using the R console in the R studio IDE, I used the R Console that gets installed when you first install R. Hopefully that helps! –  Apr 28 '21 at 04:00
  • @Jesse Kaczmarski that's interesting because I used that console too but I do not receive any meaningfull feedback. Hm, anyway, I have already reported the bug. – micsky Apr 28 '21 at 05:42
  • @micsky Oh wow that sure is interesting. [Here is a screenshot](https://imgur.com/a/pPL9q0K) of the output if you want to use it for the bug report. –  Apr 28 '21 at 13:37
  • @JesseKaczmarski I have already used your code snippet and posted the link of this whole thread in my report but thanks anyway. :) – micsky Apr 28 '21 at 15:23
  • @micsky wonderful! Hopefully this gets resolved soon because I really like Haven. –  Apr 28 '21 at 15:42
2

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")
  • True, that's one possibility to bypass the problem. But I guess this should not be the "final solution". – micsky Jun 30 '21 at 19:02
0

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

nicholas
  • 903
  • 2
  • 12