[R] For Hadley Wickham: Need for a small fix in haven::read_spss

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Mon Jul 20 15:56:15 CEST 2015


Hadley,

you've added function labelled to haven, which is great. However, when
it so happens that in SPSS a variable has no long label, your code
considers it to be NULL rather than an NA. NULL is correct, but NA
would probably be better.

For example, I've read in an SPSS file:

library(haven)
spss1 <- read_spss("SPSS_Example.sav")

varnames <- names(spss1)
mylabels <- unlist(lapply(spss1, attr, "label"))

length(varnames)
[1] 64

length(mylabels)
[1] 62


Because in this particular dataset there were 2 variables without
either variable labels or data labels.
When I run lapply(spss1, attr, "label") I see under those 2 variables
"NULL" - which is true and valid.
However,  would it be possible to have instead of NULL an NA? This way
the length of varnames and mylables would the same and one could put
them side by side (e.g., in one data frame)?


Thanks a lot!

-- 
Dimitri Liakhovitski



More information about the R-help mailing list