Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove arguments deprecated in 0.5.0 #487

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# datawizard 0.9.2

BREAKING CHANGES

* The following arguments were deprecated in 0.5.0 and are now removed:

* in `data_to_wide()`: `colnames_from`, `rows_from`, `sep`
* in `data_to_long()`: `colnames_to`
* in `data_partition()`: `training_proportion`

NEW FUNCTIONS

* `data_summary()`, to compute summary statistics of (grouped) data frames.
Expand All @@ -13,7 +21,7 @@ CHANGES
argument, to compute weighted frequency tables. `include_na` allows to include
or omit missing values from the table. Furthermore, a `by` argument was added,
to compute crosstables (#479, #481).

# datawizard 0.9.1

CHANGES
Expand Down Expand Up @@ -121,7 +129,7 @@ CHANGES
(similar to other data frame methods of transformation functions), to append
recoded variables to the input data frame instead of overwriting existing
variables.

NEW FUNCTIONS

* `rowid_as_column()` to complement `rownames_as_column()` (and to mimic
Expand Down
12 changes: 5 additions & 7 deletions R/data_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#' @param proportion Scalar (between 0 and 1) or numeric vector, indicating the
#' proportion(s) of the training set(s). The sum of `proportion` must not be
#' greater than 1. The remaining part will be used for the test set.
#' @param training_proportion Deprecated, please use `proportion`.
#' @param group A character vector indicating the name(s) of the column(s) used
#' for stratified partitioning.
#' @param seed A random number generator seed. Enter an integer (e.g. 123) so
Expand Down Expand Up @@ -50,7 +49,6 @@ data_partition <- function(data,
seed = NULL,
row_id = ".row_id",
verbose = TRUE,
training_proportion = proportion,
...) {
# validation checks
data <- .coerce_to_dataframe(data)
Expand Down Expand Up @@ -132,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
15 changes: 4 additions & 11 deletions R/data_to_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#' @param cols Identical to `select`. This argument is here to ensure compatibility
#' with `tidyr::pivot_longer()`. If both `select` and `cols` are provided, `cols`
#' is used.
#' @param colnames_to Deprecated. Use `names_to` instead.
#'
#' @return If a tibble was provided as input, `reshape_longer()` also returns a
#' tibble. Otherwise, it returns a data frame.
Expand Down Expand Up @@ -78,17 +77,10 @@ data_to_long <- function(data,
ignore_case = FALSE,
regex = FALSE,
...,
cols,
colnames_to) {
# Check args
if (!missing(colnames_to)) {
.is_deprecated("colnames_to", "names_to")
if (is.null(names_to)) {
names_to <- colnames_to
}
}
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 @@ -115,6 +107,7 @@ data_to_long <- function(data,
)
}
}
# nolint end

# nothing to select?
if (length(cols) == 0L) {
Expand Down Expand Up @@ -205,7 +198,7 @@ data_to_long <- function(data,
header = FALSE
)
names(tmp) <- paste0("V", seq_len(ncol(tmp)))
tmp[tmp == ""] <- NA
tmp[!nzchar(tmp, keepNA = TRUE)] <- NA_character_
etiennebacher marked this conversation as resolved.
Show resolved Hide resolved

stacked_data$ind <- NULL
stacked_data <- cbind(tmp, stacked_data)
Expand Down
50 changes: 12 additions & 38 deletions R/data_to_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#' missing values in the new columns created.
#' @param verbose Toggle warnings.
#' @param ... Not used for now.
#' @param colnames_from Deprecated. Use `names_from` instead.
#' @param rows_from Deprecated. Use `id_cols` instead.
#' @param sep Deprecated. Use `names_sep` instead.
#'
#' @return If a tibble was provided as input, `reshape_wider()` also returns a
#' tibble. Otherwise, it returns a data frame.
Expand Down Expand Up @@ -93,29 +90,8 @@ data_to_wide <- function(data,
names_glue = NULL,
values_fill = NULL,
verbose = TRUE,
...,
colnames_from,
rows_from,
sep) {
if (!missing(colnames_from)) {
.is_deprecated("colnames_from", "names_from")
if (is.null(names_from)) {
names_from <- colnames_from
}
}
if (!missing(rows_from)) {
.is_deprecated("rows_from", "id_cols")
...) {
if (is.null(id_cols)) {
id_cols <- rows_from
}
}
if (!missing(sep)) {
.is_deprecated("sep", "names_sep")
if (is.null(names_sep)) {
names_sep <- sep
}
}
if (is.null(id_cols)) {
id_cols <- setdiff(names(data), c(names_from, values_from))
}

Expand Down Expand Up @@ -218,28 +194,26 @@ 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 {
if (verbose) {
insight::format_error("`values_fill` must be of length 1.")
}
} else if (verbose) {
insight::format_error("`values_fill` must be of length 1.")
}
}

Expand Down
3 changes: 0 additions & 3 deletions man/data_partition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/data_to_long.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 2 additions & 14 deletions man/data_to_wide.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading