R/read_sav_labelled.R

Defines functions read_sav_labelled

Documented in read_sav_labelled

#' Read in .sav file with labelled columns
#'
#' @param file file location
#'
#' @return tibble
read_sav_labelled <- function(file){
  out <- read_sav(file)
  labels <- unlist(lapply(out,attr,'label'))
  message('Read in')
  for(i in 1:ncol(out)){
    if(is.labelled(out[[i]])){
      out[[i]] <- haven::as_factor(out[[i]])
    }
    attr(out[[i]],'label') <- labels[i]
  }
  return(out)
}
OpenSourceMindshare/surveytools documentation built on Aug. 14, 2019, 10:38 a.m.