Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Mar 12, 2024
1 parent f269c48 commit 0212f84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
10 changes: 5 additions & 5 deletions R/data_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,26 @@ data_partition <- function(data,
})

# we need to move all list elements one level higher.
if (!is.null(group)) {
if (is.null(group)) {
training_sets <- training_sets[[1]]
} else {
# for grouped training sets, we need to row-bind all sampled training
# sets from each group. currently, we have a list of data frames,
# grouped by "group"; but we want one data frame per proportion that
# contains sampled rows from all groups.
training_sets <- lapply(seq_along(proportion), function(p) {
do.call(rbind, lapply(training_sets, function(i) i[[p]]))
})
} else {
# else, just move first list element one level higher
training_sets <- training_sets[[1]]
}

# use probabilies as element names
names(training_sets) <- sprintf("p_%g", proportion)

# remove all training set id's from data, add remaining data (= test set)
all_ids <- lapply(training_sets, data_extract, select = row_id, as_data_frame = FALSE)
out <- c(
training_sets,
list(test = data[-unlist(lapply(training_sets, data_extract, select = row_id, as_data_frame = FALSE), use.names = FALSE), ])
list(test = data[-unlist(all_ids, use.names = FALSE), ])
)

lapply(out, `row.names<-`, NULL)
Expand Down
4 changes: 3 additions & 1 deletion R/data_to_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ data_to_long <- function(data,
ignore_case = FALSE,
regex = FALSE,
...,
cols) {
cols) { # nolint

# Prefer "cols" over "select" for compat with tidyr::pivot_longer
# nolint start
if (!missing(cols)) {
select <- substitute(cols)
cols <- .select_nse(
Expand All @@ -106,6 +107,7 @@ data_to_long <- function(data,
)
}
}
# nolint end

# nothing to select?
if (length(cols) == 0L) {
Expand Down
18 changes: 9 additions & 9 deletions R/data_to_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,22 @@ data_to_wide <- function(data,
if (!is.null(values_fill)) {
if (length(values_fill) == 1L) {
if (is.numeric(new_data[[values_from]])) {
if (!is.numeric(values_fill)) {
insight::format_error(paste0("`values_fill` must be of type numeric."))
} else {
if (is.numeric(values_fill)) {
new_data <- convert_na_to(new_data, replace_num = values_fill)
} else {
insight::format_error(paste0("`values_fill` must be of type numeric."))
}
} else if (is.character(new_data[[values_from]])) {
if (!is.character(values_fill)) {
insight::format_error(paste0("`values_fill` must be of type character."))
} else {
if (is.character(values_fill)) {
new_data <- convert_na_to(new_data, replace_char = values_fill)
} else {
insight::format_error(paste0("`values_fill` must be of type character."))
}
} else if (is.factor(new_data[[values_from]])) {
if (!is.factor(values_fill)) {
insight::format_error(paste0("`values_fill` must be of type factor."))
} else {
if (is.factor(values_fill)) {
new_data <- convert_na_to(new_data, replace_fac = values_fill)
} else {
insight::format_error(paste0("`values_fill` must be of type factor."))
}
}
} else {
Expand Down

0 comments on commit 0212f84

Please sign in to comment.