Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading SPSS file into R throwing error - error reading system-file header

Tags:

r

spss

Lately, I sometimes get an error when reading SPSS files using read.spss from the foreign package:

Error in read.spss("sample.sav") : error reading system-file header In addition: Warning message: In read.spss("sample.sav") : sample.sav: Bad format specifier byte (0)

I produced a tiny sample.sav file with just one variable and 3 cases that will cause the error. Download the file or use

download.file("http://134.102.100.220/~mark/sample.sav", "sample.sav")
read.spss("sample.sav")

Any ideas?

My system

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
foreign: Version 0.8-63

locale:
[1] en_US.UTF-8/de_DE.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
like image 368
Mark Heckmann Avatar asked Oct 15 '25 13:10

Mark Heckmann


1 Answers

I would use the haven package, rather than foreign, to read spss files:

require("haven")
sample <- read_spss("sample.sav")
View(sample)

You could alternatively use the sjPlot package, which uses haven to do its heavy lifting:

require("sjPlot")
sample <- sjPlot::read_spss("sample.sav", option = "haven")
View(sample)

Using sjPlot, you can also view the variable labels and values:

sjPlot::view_spss(sample)
like image 138
Phil Avatar answered Oct 18 '25 07:10

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!