Export SPSS variable labels in R studio

I am trying to extract the variable label on the spss file as a.csv file. The way I am doing right now is

   myData=read.spss("FILE PATH", to.data.frame=TRUE)
   myDataLabels <- as.data.frame(attr(myData, "variable.labels"))
   write.csv(myDataLabels,"PATH PATH TO STORE\\File Name.csv", row.names = FALSE)

This way works good for most of my spss file. However, for some spss file it has the following error when using read.spss()

error reading system-file header

I then change rhe read.spss() to read_spss() However, even the read_spss() went through, the below code can not to pull out the variable label anymore

myDataLabels <- as.data.frame(attr(myData, "variable.labels"))

The data frame create from the above line contains 0 obs and 0 variables.

I don't know if is the read_spss() causing the problem, but I don't know other way to get around the reading system-file header error .

Use the haven package. The labels are exported (if I remember correctly).

Some examples:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.