Created
June 2, 2017 21:35
-
-
Save malomarrec/a119c5f7f392778d6ad281f5847fc198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read.spss_wrapper <- function (path, verbose = FALSE){ | |
#In R 3.4.0, reading SPSS with foreign::read.spss raises errors when converting int factor levels to their labels with use.value.labels=TRUE | |
#This is a workaround. | |
list_data <- read.spss(path, to.data.frame=FALSE, use.value.labels=FALSE) | |
#list_data <- read.sav(path, to.data.frame=FALSE, use.value.labels=TRUE) | |
l1 = length(list_data) | |
indx <- sapply(list_data, is.factor) | |
list_data[indx] <- lapply(list_data[indx], function(x) { | |
levels(x) <- make.unique(levels(x)) | |
x }) | |
l2 = length(list_data) | |
if(verbose && l1 != l2){ | |
print("Warning in read.spss_wrapper: unique list is not the same length as original list") | |
} | |
return(list_data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment