Skip to content

Commit

Permalink
Merge pull request #26 from eivindhammers/master
Browse files Browse the repository at this point in the history
Fix labeling of rowid
  • Loading branch information
antaldaniel authored Dec 29, 2024
2 parents a327ac2 + ce7f9f0 commit 5240dc6
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions R/read_spss.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ read_spss <- function(file,

tmp$rowid <- paste0(id, "_", tmp$rowid)


labelled::var_label (
tmp$rowid ) <- "Unique ID"

label_orig <- lapply ( tmp, labelled::var_label )

labelled::var_label (
tmp$rowid ) <- paste0("Unique identifier in ", id)

converted <- tmp [ ! vapply ( tmp, function(x) is.null(attr(x, "labels")), logical(1)) ]
converted <- converted [ ! vapply ( converted , function(x) length(attr(x, "labels"))>0, logical(1)) ]
Expand Down Expand Up @@ -145,22 +145,14 @@ read_spss <- function(file,

return_df <- return_df %>%
select ( all_of(all_vars) )

names ( return_df )

labelling_orig <- names ( label_orig )
labelling_orig[as.numeric(which( vapply ( label_orig, is.null, logical(1)))) ] <- ""
labelling_orig


original_labels <- c(
list ( rowid = "Unique ID"),
lapply ( label_orig, function(x) ifelse(is.null(x), "", x))

)

for ( i in seq_along(return_df ) ) {
## only labellled classes will have a label
labelled::var_label ( return_df[,1] ) <- unlist(original_labels)[i]
## only labelled classes will have a label
labelled::var_label ( return_df[, i] ) <- unlist(original_labels)[i]
}

return_survey <- survey_df(return_df,
Expand Down

0 comments on commit 5240dc6

Please sign in to comment.