Search code examples
rspss

Reading SPSS (.sav) dataset into R with haven and getting errors


I'm trying to load an SPSS data set (.sav) into R using the Haven package and can't get it to work.

I'm running R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin15.6.0 (64-bit)

on OS 10.15.7

I've loaded Haven:

install.packages('haven', repos="http://cran.rstudio.com/", dependencies=TRUE)

Loaded all of the dependencies, and "install[ed] from sources the packages which need compilation."

Got lots of warnings like this one:

 Warning in install.packages :
  installation of package ‘diffobj’ had non-zero exit status 

Tried to load the file using this:

df <- read_spss('file.sav')

also tried

df <- read_sav('file.sav')

get this error:

Error in read_sav("file.sav") : 
  could not find function "read_sav"

At one point it looked like I was missing a package called Pillar, so I added that (but it still didn't work). Then I added the bit of code to downloading Haven about dependencies so figured that should resolve that.

What am I missing?

Thanks.


Solution

  • We could install the additional packages needed. Based on the OP's post, the R version is old. The current version is R 4.1.0. Would recommend to update the R and then install

    install.packages('diffobj')