Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 20, 2024
1 parent 32a0d6a commit 03001ec
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions R/data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,18 @@ data_read <- function(path,
if (is.character(i)) {
# we need this to drop haven-specific class attributes
i <- as.character(i)
} else {
} else if (!is.null(value_labels) && length(value_labels) == insight::n_unique(i)) {
# if all values are labelled, we assume factor. Use labels as levels
if (!is.null(value_labels) && length(value_labels) == insight::n_unique(i)) {
if (is.numeric(i)) {
i <- factor(i, labels = names(value_labels))
} else {
i <- factor(as.character(i), labels = names(value_labels))
}
value_labels <- NULL
attr(i, "converted_to_factor") <- TRUE
if (is.numeric(i)) {
i <- factor(i, labels = names(value_labels))
} else {
# else, fall back to numeric
i <- as.numeric(i)
i <- factor(as.character(i), labels = names(value_labels))
}
value_labels <- NULL
attr(i, "converted_to_factor") <- TRUE
} else {
# else, fall back to numeric
i <- as.numeric(i)
}

# drop unused value labels
Expand Down Expand Up @@ -310,9 +308,8 @@ data_read <- function(path,
)
}
return(out)
} else {
out <- tmp
}
out <- tmp
}

.post_process_imported_data(out, convert_factors, verbose)
Expand Down

0 comments on commit 03001ec

Please sign in to comment.