Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 7, 2024
1 parent 9f39fcd commit a25b311
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ data_read <- function(path,
value_labels <- value_labels[value_labels %in% unique(i)]

# guess variable type
if (!is.character(i)) {
if (is.character(i)) {
# we need this to drop haven-specific class attributes
i <- as.character(i)
} else {
# 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)) {
Expand All @@ -189,9 +192,6 @@ data_read <- function(path,
# else, fall back to numeric
i <- as.numeric(i)
}
} else {
# we need this to drop haven-specific class attributes
i <- as.character(i)
}

# drop unused value labels
Expand Down Expand Up @@ -302,16 +302,16 @@ data_read <- function(path,
# not. Else, tell user.
if (!is.data.frame(out)) {
tmp <- tryCatch(as.data.frame(out, stringsAsFactors = FALSE), error = function(e) NULL)
if (!is.null(tmp)) {
out <- tmp
} else {
if (is.null(tmp)) {
if (verbose) {
insight::format_warning(
paste0("Imported file is no data frame, but of class \"", class(out)[1], "\"."),
"Returning file as is. Please check if importing this file was intended."
)
}
return(out)
} else {
out <- tmp
}
}

Expand Down

0 comments on commit a25b311

Please sign in to comment.