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

Deprecate_alias #503

Closed
wants to merge 14 commits into from
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.10.0.3
Version: 0.10.0.4
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")),
Expand Down Expand Up @@ -69,7 +69,7 @@ Suggests:
tidyr,
withr
Remotes:
easystats/modelbased
easystats/modelbased, easystats/insight
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export(distribution_coef_var)
export(distribution_mode)
export(empty_columns)
export(empty_rows)
export(find_columns)
export(extract_column_names)
export(format_text)
export(get_columns)
export(kurtosis)
Expand Down
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# datawizard 0.10.1

BREAKING CHANGES

* Arguments named `group` or `group_by` are deprecated and will be removed
in a future release.
Please use `by` instead. This affects the following functions in *datawizard*.

* `data_partition()`
* `demean()` and `degroup()`
* `means_by_group()`
* `rescale_weights()`

* Following aliases are deprecated and will be removed in a future release:

* `get_columns()`, use `data_select()` instead.
* `data_find()` and `find_columns()`, use `extract_column_names()` instead.

CHANGES

* `recode_into()` is more relaxed regarding checking the type of `NA` values.
Expand Down
2 changes: 1 addition & 1 deletion R/adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#' re-added. This avoids the centering around 0 that happens by default
#' when regressing out another variable (see the examples below for a
#' visual representation of this).
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @inheritParams standardize
#'
#' @return A data frame comparable to `data`, with adjusted variables.
#'
#' @examplesIf require("bayestestR", quietly = TRUE) && require("rstanarm", quietly = TRUE) && require("gamm4", quietly = TRUE)

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.

Check warning on line 33 in R/adjust.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/adjust.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
#' adjusted_all <- adjust(attitude)
#' head(adjusted_all)
#' adjusted_one <- adjust(attitude, effect = "complaints", select = "rating")
Expand Down
2 changes: 1 addition & 1 deletion R/assign_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' `x`, the right-hand side (RHS) the associated value label. Non-matching
#' labels are omitted.
#' @param ... Currently not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @inheritSection center Selection of variables - the `select` argument
#'
Expand Down
2 changes: 1 addition & 1 deletion R/categorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#' variables are appended with new column names (using the defined suffix) to
#' the original data frame.
#' @param ... not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @inherit data_rename seealso
#'
Expand Down
2 changes: 1 addition & 1 deletion R/center.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' order, unless a named vector is given. In this case, names are matched
#' against the names of the selected variables.
#' @param ... Currently not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @inheritParams standardize
#'
#' @section Selection of variables - the `select` argument:
Expand Down Expand Up @@ -118,7 +118,7 @@
center <- TRUE
}

args <- .process_std_center(x, weights, robust, verbose, reference, center, scale = NULL)

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 121 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=121,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.
dot_args <- list(...)

if (is.null(args)) {
Expand Down Expand Up @@ -197,7 +197,7 @@
)

# process arguments
args <- .process_std_args(x, select, exclude, weights, append,

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 200 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=200,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.
append_suffix = "_c", keep_factors = force, remove_na, reference,
.center = center, .scale = NULL
)
Expand Down Expand Up @@ -249,7 +249,7 @@
verbose = verbose
)

args <- .process_grouped_df(

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 252 in R/center.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/center.R,line=252,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.
x, select, exclude, append,
append_suffix = "_c",
reference, weights, keep_factors = force
Expand Down
2 changes: 1 addition & 1 deletion R/convert_na_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
#' @param replace_num Value to replace `NA` when variable is of type numeric.
#' @param replace_char Value to replace `NA` when variable is of type character.
#' @param replace_fac Value to replace `NA` when variable is of type factor.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @rdname convert_na_to
#' @export
Expand All @@ -160,7 +160,7 @@
regex = FALSE,
verbose = TRUE,
...) {
data <- x

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

Check warning on line 163 in R/convert_na_to.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/convert_na_to.R,line=163,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.
select_nse <- .select_nse(
select,
data,
Expand Down
2 changes: 1 addition & 1 deletion R/convert_to_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param drop_levels Logical, for factors, when specific levels are replaced
#' by `NA`, should unused levels be dropped?
#' @param ... Not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @return
#' `x`, where all values in `na` are converted to `NA`.
Expand Down
2 changes: 1 addition & 1 deletion R/data_addprefix.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @rdname data_rename
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @examples
#' # Add prefix / suffix to all columns
#' head(data_addprefix(iris, "NEW_"))
Expand Down
24 changes: 12 additions & 12 deletions R/data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @param line_padding For HTML tables, the distance (in pixel) between lines.
#' @param row_color For HTML tables, the fill color for odd rows.
#' @inheritParams standardize.data.frame
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @return A formatted data frame, summarizing the content of the data frame.
#' Returned columns include the column index of the variables in the original
Expand Down Expand Up @@ -232,9 +232,9 @@

# add proportions, but not for ranges, since these are always 100%
if (is_range) {
proportions <- ""
frq_proportions <- ""
} else {
proportions <- sprintf("%.1f%%", round(100 * (frq / sum(frq)), 1))
frq_proportions <- sprintf("%.1f%%", round(100 * (frq / sum(frq)), 1))
}

# make sure we have not too long rows, e.g. for variables that
Expand All @@ -245,9 +245,9 @@
}
if (length(frq) > max_values) {
frq <- frq[1:max_values]
proportions <- proportions[1:max_values]
frq_proportions <- frq_proportions[1:max_values]
frq[max_values] <- NA
proportions[max_values] <- NA
frq_proportions[max_values] <- NA
}
if (length(values) > max_values) {
values <- values[1:max_values]
Expand All @@ -273,7 +273,7 @@
values,
value_labels,
frq,
proportions,
proportions = frq_proportions,
stringsAsFactors = FALSE
))

Expand Down Expand Up @@ -347,12 +347,12 @@
x$Prop[x$Prop == "NA" | is.na(x$Prop)] <- ""
# align only for text format
if (identical(format, "text")) {
x$Prop[x$Prop != ""] <- format(x$Prop[x$Prop != ""], justify = "right")
x$Prop[x$Prop != ""] <- format(x$Prop[x$Prop != ""], justify = "right") # nolint
}
x[["N"]][x$Prop != ""] <- sprintf(
x[["N"]][x$Prop != ""] <- sprintf( # nolint
"%s (%s)",
as.character(x[["N"]][x$Prop != ""]),
x$Prop[x$Prop != ""]
as.character(x[["N"]][x$Prop != ""]), # nolint
x$Prop[x$Prop != ""] # nolint
)
x$Prop <- NULL
}
Expand Down Expand Up @@ -388,7 +388,7 @@
# since we have each value at its own row, the HTML table contains
# horizontal borders for each cell/row. We want to remove those borders
# from rows that actually belong to one variable
separator_lines <- which(duplicated(x$.row_id) & x$N == "")
separator_lines <- which(duplicated(x$.row_id) & x$N == "") # nolint
# remove separator lines, as we don't need these for HTML tables
x <- x[-separator_lines, ]
# check row IDs, and find odd rows
Expand All @@ -405,7 +405,7 @@
out <- gt::tab_style(
out,
style = list(gt::cell_borders(sides = "top", style = "hidden")),
locations = gt::cells_body(rows = which(x$ID == ""))
locations = gt::cells_body(rows = which(x$ID == "")) # nolint
)
# highlight odd rows
if (!is.null(row_color)) {
Expand Down Expand Up @@ -466,5 +466,5 @@
N = "r"
)
align <- align[colnames(x)]
paste0(unname(align), collapse = "")

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 469 in R/data_codebook.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_codebook.R,line=469,col=3,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
}
2 changes: 1 addition & 1 deletion R/data_duplicated.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' values for that row, to help in the decision-making when
#' selecting which duplicates to keep.
#'
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @keywords duplicates
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/data_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' @param verbose Toggle warnings.
#' @param ... For use by future methods.
#'
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @details `data_extract()` can be used to select multiple variables or pull a
#' single variable from a data frame. Thus, the return value is by default not
Expand Down Expand Up @@ -134,7 +134,7 @@
}

# we definitely should have a vector here when name not NULL
if (!is.null(name)) {

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 137 in R/data_extract.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_extract.R,line=137,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
# if name indicates a variable, extract values for naming now
if (length(name) == 1L) {
name <- data[[name]]
Expand Down
2 changes: 1 addition & 1 deletion R/data_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' grouping information from a grouped data frame.
#'
#' @param data A data frame
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @return A grouped data frame, i.e. a data frame with additional information
#' about the grouping structure saved as attributes.
Expand Down Expand Up @@ -41,9 +41,9 @@
verbose = verbose
)
# create grid with combinations of all levels
grid <- as.data.frame(expand.grid(lapply(data[select], unique)))

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 44 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=44,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.
# sort grid
grid <- grid[do.call(order, grid), , drop = FALSE]

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

Check warning on line 46 in R/data_group.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_group.R,line=46,col=3,[object_overwrite_linter] 'grid' is an exported object from package 'graphics'. Avoid re-using such symbols.

.rows <- lapply(seq_len(nrow(grid)), function(i) {
as.integer(data_match(
Expand Down
24 changes: 16 additions & 8 deletions R/data_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
#'
#' Creates data partitions (for instance, a training and a test set) based on a
#' data frame that can also be stratified (i.e., evenly spread a given factor)
#' using the `group` argument.
#' using the `by` argument.
#'
#' @inheritParams data_rename
#' @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 group A character vector indicating the name(s) of the column(s) used
#' @param by 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
#' that the random sampling will be the same each time you run the function.
#' @param row_id Character string, indicating the name of the column that
#' contains the row-id's.
#' @param verbose Toggle messages and warnings.
#' @param group Deprecated. Use `by` instead.
#'
#' @return A list of data frames. The list includes one training set per given
#' proportion and the remaining data as test set. List elements of training
Expand All @@ -28,7 +29,7 @@
#' nrow(out$p_0.9)
#'
#' # Stratify by group (equal proportions of each species)
#' out <- data_partition(iris, proportion = 0.9, group = "Species")
#' out <- data_partition(iris, proportion = 0.9, by = "Species")
#' out$test
#'
#' # Create multiple partitions
Expand All @@ -38,21 +39,28 @@
#' # Create multiple partitions, stratified by group - 30% equally sampled
#' # from species in first training set, 50% in second training set and
#' # remaining 20% equally sampled from each species in test set.
#' out <- data_partition(iris, proportion = c(0.3, 0.5), group = "Species")
#' out <- data_partition(iris, proportion = c(0.3, 0.5), by = "Species")
#' lapply(out, function(i) table(i$Species))
#'
#' @inherit data_rename seealso
#' @export
data_partition <- function(data,
proportion = 0.7,
group = NULL,
by = NULL,
seed = NULL,
row_id = ".row_id",
verbose = TRUE,
group = NULL,
...) {
# validation checks
data <- .coerce_to_dataframe(data)

## TODO: remove warning in future release
if (!is.null(group)) {
by <- group
insight::format_warning("Argument `group` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
}

if (sum(proportion) > 1) {
insight::format_error("Sum of `proportion` cannot be higher than 1.")
}
Expand Down Expand Up @@ -91,12 +99,12 @@ data_partition <- function(data,

# Create list of data groups. We generally lapply over list of
# sampled row-id's by group, thus, we even create a list if not grouped.
if (is.null(group)) {
if (is.null(by)) {
indices_list <- list(seq_len(nrow(data)))
} else {
# else, split by group(s) and extract row-ids per group
indices_list <- lapply(
split(data, data[group]),
split(data, data[by]),
data_extract,
select = row_id,
as_data_frame = FALSE
Expand Down Expand Up @@ -130,7 +138,7 @@ data_partition <- function(data,
})

# we need to move all list elements one level higher.
if (is.null(group)) {
if (is.null(by)) {
training_sets <- training_sets[[1]]
} else {
# for grouped training sets, we need to row-bind all sampled training
Expand Down
2 changes: 1 addition & 1 deletion R/data_peek.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param width Maximum width of line length to display. If `NULL`, width will
#' be determined using `options()$width`.
#' @param ... not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @note To show only specific or a limited number of variables, use the
#' `select` argument, e.g. `select = 1:5` to show only the first five variables.
Expand Down
2 changes: 1 addition & 1 deletion R/data_relocate.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' character vector, indicating the name of the destination column, or a
#' numeric value, indicating the index number of the destination column.
#' If `-1`, will be added before or after the last column.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @inheritParams data_rename
#'
#' @inherit data_rename seealso
Expand Down Expand Up @@ -108,7 +108,7 @@
}
where <- min(match(before, data_cols))
position <- c(setdiff(position, where), where)
} else if (!is.null(after)) {

Check warning on line 111 in R/data_relocate.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_relocate.R,line=111,col=14,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 111 in R/data_relocate.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_relocate.R,line=111,col=14,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.

Check warning on line 111 in R/data_relocate.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_relocate.R,line=111,col=14,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
after <- after[after %in% data_cols][1] # Take first that exists (if vector is supplied)
if (length(after) != 1 || is.na(after)) {
# guess the misspelled column
Expand Down
2 changes: 1 addition & 1 deletion R/data_remove.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @rdname data_relocate
#' @examples
#' # Remove columns
Expand Down
2 changes: 1 addition & 1 deletion R/data_replicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' provided in `expand` are removed from the data frame. If `FALSE` and `expand`
#' contains missing values, the function will throw an error.
#' @param ... Currently not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @return A dataframe with each row replicated as many times as defined in `expand`.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/data_rescale.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' (change the keying/scoring direction), or to expand a range.
#'
#' @inheritParams categorize
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#' @inheritParams standardize.data.frame
#'
#' @param to Numeric vector of length 2 giving the new range that the variable
Expand Down
2 changes: 1 addition & 1 deletion R/data_reverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' usually only makes sense when factor levels are numeric, not characters.
#' @param ... Arguments passed to or from other methods.
#' @inheritParams categorize
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @inheritSection center Selection of variables - the `select` argument
#'
Expand Down
24 changes: 20 additions & 4 deletions R/data_select.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @rdname find_columns
#' @rdname extract_column_names
#' @export
get_columns <- function(data,
data_select <- function(data,
select = NULL,
exclude = NULL,
ignore_case = FALSE,
Expand Down Expand Up @@ -34,6 +34,22 @@ get_columns <- function(data,
}


#' @rdname find_columns
#' @export
data_select <- get_columns
get_columns <- function(data,
select = NULL,
exclude = NULL,
ignore_case = FALSE,
regex = FALSE,
verbose = TRUE,
...) {
insight::format_warning("Function `get_columns()` is deprecated and will be removed in a future release. Please use `data_select()` instead.") # nolint
data_select(
data,
select = select,
exclude = exclude,
ignore_case = ignore_case,
regex = regex,
verbose = verbose,
...
)
}
2 changes: 1 addition & 1 deletion R/data_separate.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#' @param convert_na Logical, if `TRUE`, character `"NA"` values are converted
#' into real `NA` values.
#' @param ... Currently not used.
#' @inheritParams find_columns
#' @inheritParams extract_column_names
#'
#' @seealso [`data_unite()`]
#'
Expand Down
Loading
Loading