diff --git a/NAMESPACE b/NAMESPACE index 10db7aa1c..28f6b175e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,11 +20,6 @@ S3method(center,factor) S3method(center,grouped_df) S3method(center,logical) S3method(center,numeric) -S3method(change_code,character) -S3method(change_code,data.frame) -S3method(change_code,default) -S3method(change_code,factor) -S3method(change_code,numeric) S3method(convert_na_to,character) S3method(convert_na_to,data.frame) S3method(convert_na_to,default) @@ -76,6 +71,11 @@ S3method(ranktransform,data.frame) S3method(ranktransform,factor) S3method(ranktransform,grouped_df) S3method(ranktransform,numeric) +S3method(recode_values,character) +S3method(recode_values,data.frame) +S3method(recode_values,default) +S3method(recode_values,factor) +S3method(recode_values,numeric) S3method(rescale,data.frame) S3method(rescale,default) S3method(rescale,grouped_df) @@ -209,6 +209,7 @@ export(object_has_rownames) export(print_html) export(print_md) export(ranktransform) +export(recode_values) export(remove_empty) export(remove_empty_columns) export(remove_empty_rows) diff --git a/NEWS.md b/NEWS.md index fbb2ee056..a50e5b58d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,9 @@ BREAKING CHANGES * New `text_format()` alias is introduced for `format_text()`, latter of which will be removed in the next release. + +* New `recode_values()` alias is introduced for `change_code()`, latter of which + will be removed in the next release. CHANGES diff --git a/R/adjust.R b/R/adjust.R index da1b617ac..9686c9cac 100644 --- a/R/adjust.R +++ b/R/adjust.R @@ -99,11 +99,12 @@ adjust <- function(data, } else { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - data, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + data, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) } # Factors diff --git a/R/categorize.R b/R/categorize.R index d4eb2b076..5e849a9cd 100644 --- a/R/categorize.R +++ b/R/categorize.R @@ -141,8 +141,10 @@ categorize.numeric <- function(x, if (is.character(split)) { split <- match.arg( split, - choices = c("median", "mean", "quantile", "equal_length", "equal_range", - "equal", "equal_distance", "range", "distance") + choices = c( + "median", "mean", "quantile", "equal_length", "equal_range", + "equal", "equal_distance", "range", "distance" + ) ) } @@ -258,11 +260,12 @@ categorize.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args( @@ -315,11 +318,12 @@ categorize.grouped_df <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args(x, select, exclude, weights = NULL, append, append_suffix = "_r", force = TRUE) diff --git a/R/center.R b/R/center.R index e60f73cbc..ee1fb9405 100644 --- a/R/center.R +++ b/R/center.R @@ -175,11 +175,12 @@ center.data.frame <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args(x, select, exclude, weights, append, @@ -227,11 +228,12 @@ center.grouped_df <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) args <- .process_grouped_df(x, select, exclude, append, append_suffix = "_c", diff --git a/R/convert_na_to.R b/R/convert_na_to.R index 24d1e04c8..1ed2b1066 100644 --- a/R/convert_na_to.R +++ b/R/convert_na_to.R @@ -159,11 +159,12 @@ convert_na_to.data.frame <- function(x, ...) { data <- x select_nse <- .select_nse(select, - data, - exclude = exclude, - ignore_case, - regex = regex, - verbose = verbose) + data, + exclude = exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # list are not covered by .select_nse if (length(select_nse) == 0) { diff --git a/R/convert_to_na.R b/R/convert_to_na.R index 352cba818..b01e6bcee 100644 --- a/R/convert_to_na.R +++ b/R/convert_to_na.R @@ -173,11 +173,12 @@ convert_to_na.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) x[select] <- lapply(x[select], convert_to_na, na = na, drop_levels = drop_levels, verbose = verbose, ...) x diff --git a/R/data_arrange.R b/R/data_arrange.R index 550c03419..6bd3d03b1 100644 --- a/R/data_arrange.R +++ b/R/data_arrange.R @@ -24,14 +24,17 @@ #' } #' @export data_arrange <- function(data, select = NULL, safe = TRUE) { - if (is.null(select) || length(select) == 0) return(data) + if (is.null(select) || length(select) == 0) { + return(data) + } # coerce to data frame? if (!is.data.frame(data)) { data <- tryCatch(as.data.frame(data), - error = function(e) { - stop("Could not coerce `data` into a data frame.", call. = FALSE) - }) + error = function(e) { + stop("Could not coerce `data` into a data frame.", call. = FALSE) + } + ) } # find which vars should be decreasing @@ -53,7 +56,9 @@ data_arrange <- function(data, select = NULL, safe = TRUE) { select <- select[-which(select %in% dont_exist)] } - if (length(select) == 0) return(data) + if (length(select) == 0) { + return(data) + } out <- data diff --git a/R/data_extract.R b/R/data_extract.R index 9591f232a..02d27067e 100644 --- a/R/data_extract.R +++ b/R/data_extract.R @@ -86,11 +86,12 @@ data_extract.data.frame <- function(data, # evaluate arguments select <- .select_nse(select, - data, - exclude = NULL, - ignore_case, - regex = regex, - verbose = verbose) + data, + exclude = NULL, + ignore_case, + regex = regex, + verbose = verbose + ) # nothing to select? if (!length(select)) { diff --git a/R/data_group.R b/R/data_group.R index 13800a405..491024c39 100644 --- a/R/data_group.R +++ b/R/data_group.R @@ -40,7 +40,8 @@ data_group <- function(data, exclude, ignore_case = ignore_case, regex = regex, - verbose = verbose) + verbose = verbose + ) # create grid with combinations of all levels grid <- as.data.frame(expand.grid(lapply(data[select], unique))) # sort grid diff --git a/R/data_relocate.R b/R/data_relocate.R index f891c1835..7b9366426 100644 --- a/R/data_relocate.R +++ b/R/data_relocate.R @@ -76,11 +76,12 @@ data_relocate <- function(data, } cols <- .select_nse(select, - data, - exclude = NULL, - ignore_case = ignore_case, - regex = regex, - verbose = verbose) + data, + exclude = NULL, + ignore_case = ignore_case, + regex = regex, + verbose = verbose + ) # save attributes att <- attributes(data) @@ -136,11 +137,12 @@ data_reorder <- function(data, verbose = TRUE, ...) { cols <- .select_nse(select, - data, - exclude = NULL, - ignore_case = ignore_case, - regex = regex, - verbose = verbose) + data, + exclude = NULL, + ignore_case = ignore_case, + regex = regex, + verbose = verbose + ) remaining_columns <- setdiff(colnames(data), cols) out <- data[c(cols, remaining_columns)] diff --git a/R/data_remove.R b/R/data_remove.R index 921cc2beb..f4f00ef1d 100644 --- a/R/data_remove.R +++ b/R/data_remove.R @@ -21,7 +21,8 @@ data_remove <- function(data, exclude = NULL, ignore_case = ignore_case, regex = regex, - verbose = verbose) + verbose = verbose + ) # nothing to remove? if (!length(select)) { diff --git a/R/data_rename.R b/R/data_rename.R index 0478ba9f2..8d95298ae 100644 --- a/R/data_rename.R +++ b/R/data_rename.R @@ -42,7 +42,7 @@ #' - Functions to rename stuff: [data_rename()], [data_rename_rows()], [data_addprefix()], [data_addsuffix()] #' - Functions to reorder or remove columns: [data_reorder()], [data_relocate()], [data_remove()] #' - Functions to reshape, pivot or rotate data frames: [data_to_long()], [data_to_wide()], [data_rotate()] -#' - Functions to recode data: [rescale()], [reverse()], [categorize()], [change_code()], [slide()] +#' - Functions to recode data: [rescale()], [reverse()], [categorize()], [recode_values()], [slide()] #' - Functions to standardize, normalize, rank-transform: [center()], [standardize()], [normalize()], [ranktransform()], [winsorize()] #' - Split and merge data frames: [data_partition()], [data_merge()] #' - Functions to find or select columns: [data_select()], [data_find()] diff --git a/R/data_rescale.R b/R/data_rescale.R index 40068356a..d06320ae8 100644 --- a/R/data_rescale.R +++ b/R/data_rescale.R @@ -130,11 +130,12 @@ rescale.grouped_df <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # dplyr < 0.8.0? if (is.null(grps)) { @@ -175,11 +176,12 @@ rescale.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # Transform the range so that it is a list now if (!is.null(range)) { diff --git a/R/data_reverse.R b/R/data_reverse.R index d6dca757d..78b70ac3d 100644 --- a/R/data_reverse.R +++ b/R/data_reverse.R @@ -141,11 +141,12 @@ reverse.grouped_df <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # dplyr < 0.8.0? if (is.null(grps)) { @@ -184,11 +185,12 @@ reverse.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # Transform the range so that it is a list now if (!is.null(range)) { diff --git a/R/data_tabulate.R b/R/data_tabulate.R index 26fecc447..563e1b070 100644 --- a/R/data_tabulate.R +++ b/R/data_tabulate.R @@ -137,11 +137,12 @@ data_tabulate.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) out <- lapply(select, function(i) { data_tabulate(x[[i]], drop_levels = drop_levels, name = i, verbose = verbose, ...) }) @@ -169,11 +170,12 @@ data_tabulate.grouped_df <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # dplyr < 0.8.0? if (is.null(grps)) { diff --git a/R/describe_distribution.R b/R/describe_distribution.R index ef66cc2df..8c421f831 100644 --- a/R/describe_distribution.R +++ b/R/describe_distribution.R @@ -379,11 +379,12 @@ describe_distribution.data.frame <- function(x, verbose = TRUE, ...) { select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # The function currently doesn't support descriptive summaries for character # or factor types. out <- do.call(rbind, lapply(x[select], function(i) { @@ -437,11 +438,12 @@ describe_distribution.grouped_df <- function(x, group_data <- expand.grid(lapply(x[group_vars], function(i) unique(sort(i)))) groups <- split(x, x[group_vars]) select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) out <- do.call(rbind, lapply(1:length(groups), function(i) { d <- describe_distribution.data.frame( diff --git a/R/normalize.R b/R/normalize.R index 5ccc3f87a..50297f8c2 100644 --- a/R/normalize.R +++ b/R/normalize.R @@ -124,11 +124,12 @@ normalize.grouped_df <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) info <- attributes(x) # dplyr >= 0.8.0 returns attribute "indices" @@ -179,11 +180,12 @@ normalize.data.frame <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) x[select] <- lapply(x[select], normalize, include_bounds = include_bounds, verbose = verbose) x diff --git a/R/ranktransform.R b/R/ranktransform.R index 439a3d8a4..300999a2d 100644 --- a/R/ranktransform.R +++ b/R/ranktransform.R @@ -113,11 +113,12 @@ ranktransform.grouped_df <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # dplyr < 0.8.0? if (is.null(grps)) { @@ -157,11 +158,12 @@ ranktransform.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) x[select] <- lapply(x[select], ranktransform, sign = sign, method = method) x diff --git a/R/change_code.R b/R/recode_values.R similarity index 86% rename from R/change_code.R rename to R/recode_values.R index 57e4da675..8a1702930 100644 --- a/R/change_code.R +++ b/R/recode_values.R @@ -1,5 +1,5 @@ #' @title Recode old values of variables into new values -#' @name change_code +#' @name recode_values #' #' @description #' This functions recodes old values into new values and can be used to to @@ -89,12 +89,12 @@ #' x <- sample(c(1:4, NA), 15, TRUE) #' table(x, useNA = "always") #' -#' out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4)) +#' out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4)) #' out #' table(out, useNA = "always") #' #' # to recode NA values, set preserve_na to FALSE -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), #' preserve_na = FALSE @@ -103,12 +103,12 @@ #' table(out, useNA = "always") #' #' # preserve na ---------- -#' out <- change_code(x, list(`0` = 1, `1` = 2:3), default = 77) +#' out <- recode_values(x, list(`0` = 1, `1` = 2:3), default = 77) #' out #' table(out, useNA = "always") #' #' # recode na into default ---------- -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`0` = 1, `1` = 2:3), #' default = 77, @@ -123,17 +123,17 @@ #' x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) #' table(x) #' -#' out <- change_code(x, list(x = "a", y = c("b", "c"))) +#' out <- recode_values(x, list(x = "a", y = c("b", "c"))) #' out #' table(out) #' -#' out <- change_code(x, list(x = "a", y = "b", z = "c")) +#' out <- recode_values(x, list(x = "a", y = "b", z = "c")) #' out #' table(out) #' -#' out <- change_code(x, list(y = "b,c"), default = 77) +#' out <- recode_values(x, list(y = "b,c"), default = 77) #' # same as -#' # change_code(x, list(y = c("b", "c")), default = 77) +#' # recode_values(x, list(y = c("b", "c")), default = 77) #' out #' table(out) #' @@ -146,7 +146,7 @@ #' stringsAsFactors = FALSE #' ) #' -#' change_code( +#' recode_values( #' d, #' recode = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = c("b", "c")), #' append = TRUE @@ -161,7 +161,7 @@ #' x <- sample(c(1:4, NA), 15, TRUE) #' table(x, useNA = "always") #' -#' out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2)) +#' out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2)) #' table(out, useNA = "always") #' #' # factors (character vectors are similar) @@ -169,19 +169,19 @@ #' x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) #' table(x) #' -#' out <- change_code(x, list(a = "x", `b, c` = "y")) +#' out <- recode_values(x, list(a = "x", `b, c` = "y")) #' table(out) #' #' # reset options #' options(data_recode_pattern = NULL) #' @export -change_code <- function(x, ...) { - UseMethod("change_code") +recode_values <- function(x, ...) { + UseMethod("recode_values") } #' @export -change_code.default <- function(x, verbose = TRUE, ...) { +recode_values.default <- function(x, verbose = TRUE, ...) { if (isTRUE(verbose)) { message(insight::format_message( paste0("Variables of class `", class(x)[1], "` can't be recoded and remain unchanged.") @@ -191,14 +191,14 @@ change_code.default <- function(x, verbose = TRUE, ...) { } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.numeric <- function(x, - recode = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.numeric <- function(x, + recode = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -274,12 +274,12 @@ change_code.numeric <- function(x, #' @export -change_code.factor <- function(x, - recode = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.factor <- function(x, + recode = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -362,12 +362,12 @@ change_code.factor <- function(x, #' @export -change_code.character <- function(x, - recode = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.character <- function(x, + recode = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -444,26 +444,27 @@ change_code.character <- function(x, } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.data.frame <- function(x, - select = NULL, - exclude = NULL, - recode = NULL, - default = NULL, - preserve_na = TRUE, - append = FALSE, - ignore_case = FALSE, - regex = FALSE, - verbose = TRUE, - ...) { +recode_values.data.frame <- function(x, + select = NULL, + exclude = NULL, + recode = NULL, + default = NULL, + preserve_na = TRUE, + append = FALSE, + ignore_case = FALSE, + regex = FALSE, + verbose = TRUE, + ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args(x, select, exclude, weights = NULL, append, append_suffix = "_r", force = TRUE) @@ -474,7 +475,7 @@ change_code.data.frame <- function(x, x[select] <- lapply( x[select], - change_code, + recode_values, recode = recode, default = default, preserve_na = preserve_na, @@ -511,3 +512,10 @@ change_code.data.frame <- function(x, ok } + + +## TODO Deprecate and remove alias later + +#' @rdname recode_values +#' @export +change_code <- recode_values diff --git a/R/slide.R b/R/slide.R index de397dc9b..da8793e4b 100644 --- a/R/slide.R +++ b/R/slide.R @@ -67,11 +67,12 @@ slide.data.frame <- function(x, ...) { # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args( diff --git a/R/standardize.R b/R/standardize.R index c0f0671a6..7b45a183b 100644 --- a/R/standardize.R +++ b/R/standardize.R @@ -251,11 +251,12 @@ standardize.data.frame <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # process arguments args <- .process_std_args(x, select, exclude, weights, append, @@ -308,11 +309,12 @@ standardize.grouped_df <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) args <- .process_grouped_df(x, select, exclude, append, append_suffix = "_z", diff --git a/R/format_text.R b/R/text_format.R similarity index 100% rename from R/format_text.R rename to R/text_format.R diff --git a/R/to_factor.R b/R/to_factor.R index 7d051a96b..55d4648bc 100644 --- a/R/to_factor.R +++ b/R/to_factor.R @@ -93,11 +93,12 @@ to_factor.data.frame <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # drop factors, when append is not FALSE if (!isFALSE(append)) { diff --git a/R/to_numeric.R b/R/to_numeric.R index 94192b5ac..9ce75bb82 100644 --- a/R/to_numeric.R +++ b/R/to_numeric.R @@ -71,11 +71,12 @@ to_numeric.data.frame <- function(x, # evaluate arguments select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) # drop numerics, when append is not FALSE if (!isFALSE(append)) { diff --git a/R/unnormalize.R b/R/unnormalize.R index 96eab35b0..e0ea0cf13 100644 --- a/R/unnormalize.R +++ b/R/unnormalize.R @@ -46,11 +46,12 @@ unnormalize.data.frame <- function(x, ...) { # evaluate select/exclude, may be select-helpers select <- .select_nse(select, - x, - exclude, - ignore_case, - regex = regex, - verbose = verbose) + x, + exclude, + ignore_case, + regex = regex, + verbose = verbose + ) x[select] <- lapply(x[select], unnormalize, verbose = verbose) x diff --git a/WIP/data_arrange2.R b/WIP/data_arrange2.R index 2564f081f..915c7ef23 100644 --- a/WIP/data_arrange2.R +++ b/WIP/data_arrange2.R @@ -33,7 +33,6 @@ data_arrange2 <- function(data, descending = NULL, ignore_case = FALSE, ...) { - # evaluate arguments select <- .select_nse(select, data, exclude, ignore_case) diff --git a/WIP/data_recode_intuitive.R b/WIP/data_recode_intuitive.R index ad79a1768..72294f1ba 100644 --- a/WIP/data_recode_intuitive.R +++ b/WIP/data_recode_intuitive.R @@ -1,5 +1,5 @@ #' @title Recode old values of variables into new values -#' @name change_code +#' @name recode_values #' #' @description #' This functions recodes old values into new values and can be used to to @@ -79,12 +79,12 @@ #' x <- sample(c(1:4, NA), 15, TRUE) #' table(x, useNA = "always") #' -#' out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2)) +#' out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2)) #' out #' table(out, useNA = "always") #' #' # to recode NA values, set preserve_na to FALSE -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`1` = 0, `2:3` = 1, `4` = 2, `NA` = 9), #' preserve_na = FALSE @@ -93,12 +93,12 @@ #' table(out, useNA = "always") #' #' # preserve na -#' out <- change_code(x, list(`1` = 0, `2:3` = 1), default = 77) +#' out <- recode_values(x, list(`1` = 0, `2:3` = 1), default = 77) #' out #' table(out, useNA = "always") #' #' # recode na into default -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`1` = 0, `2:3` = 1), #' default = 77, @@ -113,15 +113,15 @@ #' x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) #' table(x) #' -#' out <- change_code(x, list(a = "x", `b, c` = "y")) +#' out <- recode_values(x, list(a = "x", `b, c` = "y")) #' out #' table(out) #' -#' out <- change_code(x, list(a = "x", b = "y", c = "z")) +#' out <- recode_values(x, list(a = "x", b = "y", c = "z")) #' out #' table(out) #' -#' out <- change_code(x, list(`b, c` = "y"), default = 77) +#' out <- recode_values(x, list(`b, c` = "y"), default = 77) #' out #' table(out) #' @@ -134,20 +134,20 @@ #' stringsAsFactors = FALSE #' ) #' -#' change_code( +#' recode_values( #' d, #' recodes = list(`1` = 0, `2:3` = 1, `4` = 2, a = "x", `b, c` = "y"), #' force = TRUE, #' append = TRUE #' ) #' @export -change_code <- function(x, ...) { - UseMethod("change_code") +recode_values <- function(x, ...) { + UseMethod("recode_values") } #' @export -change_code.default <- function(x, verbose = TRUE, ...) { +recode_values.default <- function(x, verbose = TRUE, ...) { if (isTRUE(verbose)) { message(insight::format_message(paste0("Variables of class '", class(x)[1], "' can't be recoded and remain unchanged."))) } @@ -155,14 +155,14 @@ change_code.default <- function(x, verbose = TRUE, ...) { } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.numeric <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.numeric <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -229,12 +229,12 @@ change_code.numeric <- function(x, #' @export -change_code.factor <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.factor <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -297,12 +297,12 @@ change_code.factor <- function(x, #' @export -change_code.character <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.character <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -358,19 +358,19 @@ change_code.character <- function(x, } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.data.frame <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - force = FALSE, - append = FALSE, - select = NULL, - exclude = NULL, - ignore_case = FALSE, - verbose = TRUE, - ...) { +recode_values.data.frame <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + force = FALSE, + append = FALSE, + select = NULL, + exclude = NULL, + ignore_case = FALSE, + verbose = TRUE, + ...) { # evaluate arguments select <- .select_nse(select, x, exclude, ignore_case) @@ -383,7 +383,7 @@ change_code.data.frame <- function(x, x[select] <- lapply( x[select], - change_code, + recode_values, recodes = recodes, default = default, preserve_na = preserve_na, diff --git a/WIP/data_recode_strange.R b/WIP/data_recode_strange.R index eec94b740..be65f7a52 100644 --- a/WIP/data_recode_strange.R +++ b/WIP/data_recode_strange.R @@ -1,5 +1,5 @@ #' @title Recode old values of variables into new values -#' @name change_code +#' @name recode_values #' #' @description #' This functions recodes old values into new values and can be used to to @@ -81,12 +81,12 @@ #' x <- sample(c(1:4, NA), 15, TRUE) #' table(x, useNA = "always") #' -#' out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4)) +#' out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4)) #' out #' table(out, useNA = "always") #' #' # to recode NA values, set preserve_na to FALSE -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), #' preserve_na = FALSE @@ -95,12 +95,12 @@ #' table(out, useNA = "always") #' #' # preserve na -#' out <- change_code(x, list(`0` = 1, `1` = 2:3), default = 77) +#' out <- recode_values(x, list(`0` = 1, `1` = 2:3), default = 77) #' out #' table(out, useNA = "always") #' #' # recode na into default -#' out <- change_code( +#' out <- recode_values( #' x, #' list(`0` = 1, `1` = 2:3), #' default = 77, @@ -115,17 +115,17 @@ #' x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) #' table(x) #' -#' out <- change_code(x, list(x = "a", y = c("b", "c"))) +#' out <- recode_values(x, list(x = "a", y = c("b", "c"))) #' out #' table(out) #' -#' out <- change_code(x, list(x = "a", y = "b", z = "c")) +#' out <- recode_values(x, list(x = "a", y = "b", z = "c")) #' out #' table(out) #' -#' out <- change_code(x, list(y = "b,c"), default = 77) +#' out <- recode_values(x, list(y = "b,c"), default = 77) #' # same as -#' # change_code(x, list(y = c("b", "c")), default = 77) +#' # recode_values(x, list(y = c("b", "c")), default = 77) #' out #' table(out) #' @@ -138,20 +138,20 @@ #' stringsAsFactors = FALSE #' ) #' -#' change_code( +#' recode_values( #' d, #' recodes = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = c("b", "c")), #' force = TRUE, #' append = TRUE #' ) #' @export -change_code <- function(x, ...) { - UseMethod("change_code") +recode_values <- function(x, ...) { + UseMethod("recode_values") } #' @export -change_code.default <- function(x, verbose = TRUE, ...) { +recode_values.default <- function(x, verbose = TRUE, ...) { if (isTRUE(verbose)) { message(insight::format_message(paste0("Variables of class '", class(x)[1], "' can't be recoded and remain unchanged."))) } @@ -159,14 +159,14 @@ change_code.default <- function(x, verbose = TRUE, ...) { } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.numeric <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.numeric <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -233,12 +233,12 @@ change_code.numeric <- function(x, #' @export -change_code.factor <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.factor <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -302,12 +302,12 @@ change_code.factor <- function(x, #' @export -change_code.character <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - verbose = TRUE, - ...) { +recode_values.character <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + verbose = TRUE, + ...) { # save original_x <- x @@ -364,19 +364,19 @@ change_code.character <- function(x, } -#' @rdname change_code +#' @rdname recode_values #' @export -change_code.data.frame <- function(x, - recodes = NULL, - default = NULL, - preserve_na = TRUE, - force = FALSE, - append = FALSE, - select = NULL, - exclude = NULL, - ignore_case = FALSE, - verbose = TRUE, - ...) { +recode_values.data.frame <- function(x, + recodes = NULL, + default = NULL, + preserve_na = TRUE, + force = FALSE, + append = FALSE, + select = NULL, + exclude = NULL, + ignore_case = FALSE, + verbose = TRUE, + ...) { # evaluate arguments select <- .select_nse(select, x, exclude, ignore_case) @@ -389,7 +389,7 @@ change_code.data.frame <- function(x, x[select] <- lapply( x[select], - change_code, + recode_values, recodes = recodes, default = default, preserve_na = preserve_na, diff --git a/_pkgdown.yml b/_pkgdown.yml index 511749825..d376bc555 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -25,7 +25,7 @@ reference: desc: Functions for transforming variables contents: - categorize - - change_code + - recode_values - rescale - reverse - slide diff --git a/man/categorize.Rd b/man/categorize.Rd index 7cf61e40d..0be048d22 100644 --- a/man/categorize.Rd +++ b/man/categorize.Rd @@ -216,7 +216,7 @@ categorize(x, "equal_length", n_groups = 3, labels = c("low", "mid", "high")) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_match.Rd b/man/data_match.Rd index 94dfda2c8..ef7813757 100644 --- a/man/data_match.Rd +++ b/man/data_match.Rd @@ -101,7 +101,7 @@ data_filter(mtcars, 5:10) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_merge.Rd b/man/data_merge.Rd index 80d17f8d5..5934f8fc6 100644 --- a/man/data_merge.Rd +++ b/man/data_merge.Rd @@ -184,7 +184,7 @@ data_merge(list(x, y, z), join = "bind", by = "id", id = "source") \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_partition.Rd b/man/data_partition.Rd index 2b8368207..49ae37536 100644 --- a/man/data_partition.Rd +++ b/man/data_partition.Rd @@ -74,7 +74,7 @@ lapply(out, function(i) table(i$Species)) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_relocate.Rd b/man/data_relocate.Rd index e257c1a29..47c9c8dde 100644 --- a/man/data_relocate.Rd +++ b/man/data_relocate.Rd @@ -134,7 +134,7 @@ head(data_remove(iris, starts_with("Sepal"))) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_rename.Rd b/man/data_rename.Rd index 68047c99f..724f8e306 100644 --- a/man/data_rename.Rd +++ b/man/data_rename.Rd @@ -122,7 +122,7 @@ head(data_rename(iris, paste0("Var", 1:5))) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_rotate.Rd b/man/data_rotate.Rd index 5970b2494..4d55b04f3 100644 --- a/man/data_rotate.Rd +++ b/man/data_rotate.Rd @@ -58,7 +58,7 @@ data_rotate(x, colnames = "c") \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_to_long.Rd b/man/data_to_long.Rd index 0d24cb91c..f0e4f28dd 100644 --- a/man/data_to_long.Rd +++ b/man/data_to_long.Rd @@ -169,7 +169,7 @@ if (require("psych")) { \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/data_to_wide.Rd b/man/data_to_wide.Rd index c072a882c..417a1a930 100644 --- a/man/data_to_wide.Rd +++ b/man/data_to_wide.Rd @@ -139,7 +139,7 @@ reshape_wider( \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/find_columns.Rd b/man/find_columns.Rd index 5a969fa13..705c6e900 100644 --- a/man/find_columns.Rd +++ b/man/find_columns.Rd @@ -164,7 +164,7 @@ find_columns(iris, numeric_mean_35) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/change_code.Rd b/man/recode_values.Rd similarity index 92% rename from man/change_code.Rd rename to man/recode_values.Rd index c7f3e91f4..33784968a 100644 --- a/man/change_code.Rd +++ b/man/recode_values.Rd @@ -1,14 +1,15 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/change_code.R -\name{change_code} +% Please edit documentation in R/recode_values.R +\name{recode_values} +\alias{recode_values} +\alias{recode_values.numeric} +\alias{recode_values.data.frame} \alias{change_code} -\alias{change_code.numeric} -\alias{change_code.data.frame} \title{Recode old values of variables into new values} \usage{ -change_code(x, ...) +recode_values(x, ...) -\method{change_code}{numeric}( +\method{recode_values}{numeric}( x, recode = NULL, default = NULL, @@ -17,7 +18,7 @@ change_code(x, ...) ... ) -\method{change_code}{data.frame}( +\method{recode_values}{data.frame}( x, select = NULL, exclude = NULL, @@ -30,6 +31,8 @@ change_code(x, ...) verbose = TRUE, ... ) + +change_code(x, ...) } \arguments{ \item{x}{A data frame, numeric or character vector, or factor.} @@ -186,12 +189,12 @@ set.seed(123) x <- sample(c(1:4, NA), 15, TRUE) table(x, useNA = "always") -out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4)) +out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4)) out table(out, useNA = "always") # to recode NA values, set preserve_na to FALSE -out <- change_code( +out <- recode_values( x, list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), preserve_na = FALSE @@ -200,12 +203,12 @@ out table(out, useNA = "always") # preserve na ---------- -out <- change_code(x, list(`0` = 1, `1` = 2:3), default = 77) +out <- recode_values(x, list(`0` = 1, `1` = 2:3), default = 77) out table(out, useNA = "always") # recode na into default ---------- -out <- change_code( +out <- recode_values( x, list(`0` = 1, `1` = 2:3), default = 77, @@ -220,17 +223,17 @@ set.seed(123) x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) table(x) -out <- change_code(x, list(x = "a", y = c("b", "c"))) +out <- recode_values(x, list(x = "a", y = c("b", "c"))) out table(out) -out <- change_code(x, list(x = "a", y = "b", z = "c")) +out <- recode_values(x, list(x = "a", y = "b", z = "c")) out table(out) -out <- change_code(x, list(y = "b,c"), default = 77) +out <- recode_values(x, list(y = "b,c"), default = 77) # same as -# change_code(x, list(y = c("b", "c")), default = 77) +# recode_values(x, list(y = c("b", "c")), default = 77) out table(out) @@ -243,7 +246,7 @@ d <- data.frame( stringsAsFactors = FALSE ) -change_code( +recode_values( d, recode = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = c("b", "c")), append = TRUE @@ -258,7 +261,7 @@ set.seed(123) x <- sample(c(1:4, NA), 15, TRUE) table(x, useNA = "always") -out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2)) +out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2)) table(out, useNA = "always") # factors (character vectors are similar) @@ -266,7 +269,7 @@ set.seed(123) x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) table(x) -out <- change_code(x, list(a = "x", `b, c` = "y")) +out <- recode_values(x, list(a = "x", `b, c` = "y")) table(out) # reset options @@ -277,7 +280,7 @@ options(data_recode_pattern = NULL) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/slide.Rd b/man/slide.Rd index 36a0cc407..1e4e03d92 100644 --- a/man/slide.Rd +++ b/man/slide.Rd @@ -122,7 +122,7 @@ sapply(mtcars, min) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/man/text_format.Rd b/man/text_format.Rd index 09db368e9..87f045193 100644 --- a/man/text_format.Rd +++ b/man/text_format.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/format_text.R +% Please edit documentation in R/text_format.R \name{text_format} \alias{text_format} \alias{format_text} diff --git a/man/winsorize.Rd b/man/winsorize.Rd index 2757f450e..8d52628ae 100644 --- a/man/winsorize.Rd +++ b/man/winsorize.Rd @@ -79,7 +79,7 @@ winsorize(iris, threshold = 0.2) \item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} \item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} \item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} -\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=change_code]{change_code()}}, \code{\link[=slide]{slide()}} +\item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} \item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=data_find]{data_find()}} diff --git a/tests/testthat/test-adjust.R b/tests/testthat/test-adjust.R index f7ef768fa..9916280b8 100644 --- a/tests/testthat/test-adjust.R +++ b/tests/testthat/test-adjust.R @@ -21,7 +21,8 @@ test_that("adjust", { test_that("adjust regex", { expect_equal( adjust(mtcars, select = "pg", regex = TRUE), - adjust(mtcars, select = "mpg")) + adjust(mtcars, select = "mpg") + ) expect_equal( adjust(mtcars, select = "pg$", regex = TRUE), adjust(mtcars, select = "mpg") diff --git a/tests/testthat/test-center.R b/tests/testthat/test-center.R index bb8a30085..6ccdb4232 100644 --- a/tests/testthat/test-center.R +++ b/tests/testthat/test-center.R @@ -131,7 +131,8 @@ test_that("center, factors (grouped data)", { test_that("center regex", { expect_equal( center(mtcars, select = "pg", regex = TRUE)$mpg, - center(mtcars$mpg)) + center(mtcars$mpg) + ) expect_equal( center(mtcars, select = "pg$", regex = TRUE)$mpg, center(mtcars$mpg) diff --git a/tests/testthat/test-convert_na_to.R b/tests/testthat/test-convert_na_to.R index f68262caa..da8a41e6a 100644 --- a/tests/testthat/test-convert_na_to.R +++ b/tests/testthat/test-convert_na_to.R @@ -413,7 +413,8 @@ test_that("data_rename preserves attributes", { test_that("convert_na_to regex", { expect_equal( convert_na_to(airquality, replacement = 0, select = "zone", regex = TRUE), - convert_na_to(airquality, replacement = 0, select = "Ozone")) + convert_na_to(airquality, replacement = 0, select = "Ozone") + ) expect_equal( convert_na_to(airquality, replacement = 0, select = "zone$", regex = TRUE), convert_na_to(airquality, replacement = 0, select = "Ozone") diff --git a/tests/testthat/test-convert_to_na.R b/tests/testthat/test-convert_to_na.R index 0cc960fad..bca12d7c6 100644 --- a/tests/testthat/test-convert_to_na.R +++ b/tests/testthat/test-convert_to_na.R @@ -95,7 +95,8 @@ test_that("convert_to_na other classes", { test_that("convert_to_na regex", { expect_equal( convert_to_na(mtcars, na = 4, select = "arb", regex = TRUE), - convert_to_na(mtcars, na = 4, select = "carb")) + convert_to_na(mtcars, na = 4, select = "carb") + ) expect_equal( convert_to_na(mtcars, na = 4, select = "arb$", regex = TRUE), convert_to_na(mtcars, na = 4, select = "carb") diff --git a/tests/testthat/test-data_cut.R b/tests/testthat/test-data_cut.R index a18192103..3ae781bd8 100644 --- a/tests/testthat/test-data_cut.R +++ b/tests/testthat/test-data_cut.R @@ -179,6 +179,6 @@ test_that("recode numeric", { test_that("categorize regex", { expect_equal( categorize(mtcars, select = "pg", regex = TRUE), - categorize(mtcars, select = "mpg")) + categorize(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-data_extract.R b/tests/testthat/test-data_extract.R index 5458c5ff0..5e80cfd98 100644 --- a/tests/testthat/test-data_extract.R +++ b/tests/testthat/test-data_extract.R @@ -136,8 +136,10 @@ test_that("data_extract extract, pull", { test_that("data_extract regex", { expect_equal( data_extract(mtcars, select = "pg", regex = TRUE), - data_extract(mtcars, select = "mpg")) + data_extract(mtcars, select = "mpg") + ) expect_equal( data_extract(mtcars, select = "pg$", regex = TRUE), - data_extract(mtcars, select = "mpg")) + data_extract(mtcars, select = "mpg") + ) }) diff --git a/tests/testthat/test-data_group.R b/tests/testthat/test-data_group.R index 178dd476c..23d610997 100644 --- a/tests/testthat/test-data_group.R +++ b/tests/testthat/test-data_group.R @@ -43,6 +43,6 @@ test_that("data_group attributes", { test_that("data_group regex", { expect_equal( attributes(data_group(mtcars, select = "yl", regex = TRUE))$groups[[1]], - sort(unique(mtcars$cyl))) + sort(unique(mtcars$cyl)) + ) }) - diff --git a/tests/testthat/test-data_recode.R b/tests/testthat/test-data_recode.R index 66497b686..b1336913b 100644 --- a/tests/testthat/test-data_recode.R +++ b/tests/testthat/test-data_recode.R @@ -10,15 +10,15 @@ set.seed(123) x <- sample(c(1:4, NA), 15, TRUE) test_that("recode numeric", { - out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2)) + out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2)) expect_equal(out, c(1, 1, 1, 1, 1, NA, 2, 0, 1, 1, NA, 1, 1, 0, 2), ignore_attr = TRUE) - out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2, `NA` = 9), preserve_na = FALSE) + out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2, `NA` = 9), preserve_na = FALSE) expect_equal(out, c(1, 1, 1, 1, 1, 9, 2, 0, 1, 1, 9, 1, 1, 0, 2), ignore_attr = TRUE) - out <- change_code(x, list(`1` = 0, `2:3` = 1, `4` = 2, `NA` = 9)) + out <- recode_values(x, list(`1` = 0, `2:3` = 1, `4` = 2, `NA` = 9)) expect_equal(out, c(1, 1, 1, 1, 1, NA, 2, 0, 1, 1, NA, 1, 1, 0, 2), ignore_attr = TRUE) - out <- change_code(x, list(`1` = 0, `2` = 1), default = 99, preserve_na = FALSE) + out <- recode_values(x, list(`1` = 0, `2` = 1), default = 99, preserve_na = FALSE) expect_equal(out, c(99, 99, 1, 1, 99, 99, 99, 0, 1, 99, 99, 99, 99, 0, 99), ignore_attr = TRUE) - out <- change_code(x, list(`1` = 0, `2` = 1), default = 99) + out <- recode_values(x, list(`1` = 0, `2` = 1), default = 99) expect_equal(out, c(99, 99, 1, 1, 99, NA, 99, 0, 1, 99, NA, 99, 99, 0, 99), ignore_attr = TRUE) }) @@ -30,7 +30,7 @@ set.seed(123) x <- as.Date("2022-01-01") test_that("recode date", { - expect_message(change_code(x)) + expect_message(recode_values(x)) }) @@ -41,7 +41,7 @@ set.seed(123) x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) test_that("recode factor", { - out <- change_code(x, list(a = "x", `b, c` = "y")) + out <- recode_values(x, list(a = "x", `b, c` = "y")) expect_equal( out, structure(c( @@ -50,7 +50,7 @@ test_that("recode factor", { ), .Label = c("x", "y"), class = "factor"), ignore_attr = TRUE ) - out <- change_code(x, list(a = "x", `b, c` = "y")) + out <- recode_values(x, list(a = "x", `b, c` = "y")) expect_equal( out, structure(c( @@ -65,25 +65,25 @@ set.seed(123) x <- as.factor(sample(c("a", "b", "c", NA_character_), 15, TRUE)) test_that("recode factor", { - out <- change_code(x, list(a = "x", `b, c` = "y")) + out <- recode_values(x, list(a = "x", `b, c` = "y")) expect_equal( as.character(out), c("y", "y", "y", "y", "y", "y", "y", "y", "y", "x", NA, "y", "y", "x", "y"), ignore_attr = TRUE ) - out <- change_code(x, list(a = "x", b = NA)) + out <- recode_values(x, list(a = "x", b = NA)) expect_equal( as.character(out), c("c", "c", "c", NA, "c", NA, NA, NA, "c", "x", NA, NA, NA, "x", NA), ignore_attr = TRUE ) - out <- change_code(x, list(a = "x", b = "y"), default = "zz") + out <- recode_values(x, list(a = "x", b = "y"), default = "zz") expect_equal( as.character(out), c("zz", "zz", "zz", "y", "zz", "y", "y", "y", "zz", "x", NA, "y", "y", "x", "y"), ignore_attr = TRUE ) - out <- change_code(x, list(a = "x", b = "y"), default = "zz", preserve_na = FALSE) + out <- recode_values(x, list(a = "x", b = "y"), default = "zz", preserve_na = FALSE) expect_equal( as.character(out), c("zz", "zz", "zz", "y", "zz", "y", "y", "y", "zz", "x", "zz", "y", "y", "x", "y"), @@ -99,7 +99,7 @@ set.seed(123) x <- as.character(sample(c("a", "b", "c"), 15, TRUE)) test_that("recode character", { - out <- change_code(x, list(a = "x", `b, c` = "y")) + out <- recode_values(x, list(a = "x", `b, c` = "y")) expect_equal( out, c("y", "y", "y", "y", "y", "y", "y", "y", "y", "x", "y", "y", "x", "y", "y"), @@ -119,7 +119,7 @@ d <- data.frame( ) test_that("recode data.frame", { - out <- change_code( + out <- recode_values( d, recode = list(`1` = 0, `2:3` = 1, `4` = 2, a = "x", `b, c` = "y"), ) @@ -138,7 +138,7 @@ test_that("recode data.frame", { ignore_attr = TRUE ) - out <- change_code( + out <- recode_values( d, recode = list(`1` = 0, `2:3` = 1, `4` = 2, a = "x", `b, c` = "y"), ) @@ -157,7 +157,7 @@ test_that("recode data.frame", { ignore_attr = TRUE ) - out <- change_code( + out <- recode_values( d, recode = list(`1` = 0, `2:3` = 1, `4` = 2, a = "x", `b, c` = "y"), select = is.numeric() @@ -188,16 +188,16 @@ set.seed(123) x <- sample(c(1:4, NA), 15, TRUE) test_that("recode numeric", { - out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4)) + out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4)) expect_equal(out, c(1, 1, 1, 1, 1, NA, 2, 0, 1, 1, NA, 1, 1, 0, 2), ignore_attr = TRUE) - out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), preserve_na = FALSE) + out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), preserve_na = FALSE) expect_equal(out, c(1, 1, 1, 1, 1, 9, 2, 0, 1, 1, 9, 1, 1, 0, 2), ignore_attr = TRUE) - out <- change_code(x, list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), preserve_na = TRUE) + out <- recode_values(x, list(`0` = 1, `1` = 2:3, `2` = 4, `9` = NA), preserve_na = TRUE) expect_equal(out, c(1, 1, 1, 1, 1, NA, 2, 0, 1, 1, NA, 1, 1, 0, 2), ignore_attr = TRUE) }) test_that("recode, recode-arg is named list", { - expect_warning(expect_equal(change_code(x, recode = c(`0` = 1, `1` = 2:3, `2` = 4)), x)) + expect_warning(expect_equal(recode_values(x, recode = c(`0` = 1, `1` = 2:3, `2` = 4)), x)) }) @@ -205,7 +205,7 @@ set.seed(123) x <- as.factor(sample(c("a", "b", "c"), 15, TRUE)) test_that("recode factor", { - out <- change_code(x, list(x = "a", y = "b, c")) + out <- recode_values(x, list(x = "a", y = "b, c")) expect_equal( out, structure(c( @@ -214,7 +214,7 @@ test_that("recode factor", { ), .Label = c("x", "y"), class = "factor"), ignore_attr = TRUE ) - out <- change_code(x, list(x = "a", y = c("b", "c"))) + out <- recode_values(x, list(x = "a", y = c("b", "c"))) expect_equal( out, structure(c( @@ -226,7 +226,7 @@ test_that("recode factor", { }) test_that("recode, recode-arg is named list", { - expect_warning(expect_equal(change_code(x, recode = c(x = "a", y = "b, c")), x)) + expect_warning(expect_equal(recode_values(x, recode = c(x = "a", y = "b, c")), x)) }) @@ -238,7 +238,7 @@ d <- data.frame( ) test_that("recode data.frame", { - out <- change_code( + out <- recode_values( d, recode = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = "b, c"), ) @@ -257,7 +257,7 @@ test_that("recode data.frame", { ignore_attr = TRUE ) - out <- change_code( + out <- recode_values( d, recode = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = c("b", "c")), ) @@ -276,7 +276,7 @@ test_that("recode data.frame", { ignore_attr = TRUE ) - out <- change_code( + out <- recode_values( d, recode = list(`0` = 1, `1` = 2:3, `2` = 4, x = "a", y = c("b", "c")), select = is.numeric() @@ -298,10 +298,13 @@ test_that("recode data.frame", { }) # select helpers ------------------------------ -test_that("change_code regex", { +test_that("recode_values regex", { expect_equal( - change_code(iris, select = "ies", regex = TRUE, recode = list( - Group1 = "setosa", Group2 = "versicolor", Group3 = "virginica")), - change_code(iris, select = "Species", recode = list( - Group1 = "setosa", Group2 = "versicolor", Group3 = "virginica"))) + recode_values(iris, select = "ies", regex = TRUE, recode = list( + Group1 = "setosa", Group2 = "versicolor", Group3 = "virginica" + )), + recode_values(iris, select = "Species", recode = list( + Group1 = "setosa", Group2 = "versicolor", Group3 = "virginica" + )) + ) }) diff --git a/tests/testthat/test-data_relocate.R b/tests/testthat/test-data_relocate.R index 8b47fede6..fd67c226b 100644 --- a/tests/testthat/test-data_relocate.R +++ b/tests/testthat/test-data_relocate.R @@ -87,6 +87,6 @@ test_that("data_relocate preserves attributes", { test_that("data_relocate regex", { expect_equal( names(data_relocate(mtcars, select = "pg", regex = TRUE, after = "carb"))[11], - "mpg") + "mpg" + ) }) - diff --git a/tests/testthat/test-data_remove.R b/tests/testthat/test-data_remove.R index 9a15f6eff..c83294fbf 100644 --- a/tests/testthat/test-data_remove.R +++ b/tests/testthat/test-data_remove.R @@ -124,8 +124,6 @@ test_that("data_remove preserves attributes", { test_that("data_remove regex", { expect_equal( names(data_remove(mtcars, select = "pg", regex = TRUE)), - names(mtcars[-(1)])) + names(mtcars[-(1)]) + ) }) - - - diff --git a/tests/testthat/test-data_rescale.R b/tests/testthat/test-data_rescale.R index 687edd0ae..bb8824268 100644 --- a/tests/testthat/test-data_rescale.R +++ b/tests/testthat/test-data_rescale.R @@ -66,6 +66,6 @@ test_that("rescale works with select helpers", { test_that("data_rescale regex", { expect_equal( rescale(mtcars, select = "pg", regex = TRUE)$mpg, - rescale(mtcars, select = "mpg")$mpg) + rescale(mtcars, select = "mpg")$mpg + ) }) - diff --git a/tests/testthat/test-data_reverse.R b/tests/testthat/test-data_reverse.R index 9d8435caa..ee49b4865 100644 --- a/tests/testthat/test-data_reverse.R +++ b/tests/testthat/test-data_reverse.R @@ -387,6 +387,6 @@ test_that("reverse works with data frames containing NAs (grouped data)", { test_that("reverse regex", { expect_equal( reverse(mtcars, select = "arb", regex = TRUE), - reverse(mtcars, select = "carb")) + reverse(mtcars, select = "carb") + ) }) - diff --git a/tests/testthat/test-data_shift.R b/tests/testthat/test-data_shift.R index e016a1d77..857075c4b 100644 --- a/tests/testthat/test-data_shift.R +++ b/tests/testthat/test-data_shift.R @@ -31,6 +31,6 @@ test_that("slide", { test_that("slide regex", { expect_equal( slide(mtcars, select = "pg", regex = TRUE), - slide(mtcars, select = "mpg")) + slide(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-data_tabulate.R b/tests/testthat/test-data_tabulate.R index 1fed9be9a..def083139 100644 --- a/tests/testthat/test-data_tabulate.R +++ b/tests/testthat/test-data_tabulate.R @@ -315,6 +315,6 @@ if (requireNamespace("poorman", quietly = TRUE)) { test_that("data_tabulate regex", { expect_equal( data_tabulate(mtcars, select = "arb", regex = TRUE), - data_tabulate(mtcars, select = "carb")) + data_tabulate(mtcars, select = "carb") + ) }) - diff --git a/tests/testthat/test-data_to_factor.R b/tests/testthat/test-data_to_factor.R index be1c2f330..e3fedf9e0 100644 --- a/tests/testthat/test-data_to_factor.R +++ b/tests/testthat/test-data_to_factor.R @@ -55,7 +55,8 @@ test_that("to_factor", { test_that("to_factor regex", { expect_equal( to_factor(mtcars, select = "yl", regex = TRUE), - to_factor(mtcars, select = "cyl")) + to_factor(mtcars, select = "cyl") + ) expect_equal( to_factor(mtcars, select = "yl$", regex = TRUE), to_factor(mtcars, select = "cyl") diff --git a/tests/testthat/test-data_to_numeric.R b/tests/testthat/test-data_to_numeric.R index 306d6bf91..e17064ae8 100644 --- a/tests/testthat/test-data_to_numeric.R +++ b/tests/testthat/test-data_to_numeric.R @@ -151,6 +151,6 @@ test_that("convert factor to numeric, dummy factors, with NA", { test_that("to_numeric regex", { expect_equal( to_numeric(mtcars, select = "pg", regex = TRUE), - to_numeric(mtcars, select = "mpg")) + to_numeric(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-describe_distribution.R b/tests/testthat/test-describe_distribution.R index 6806c511d..6e45381e2 100644 --- a/tests/testthat/test-describe_distribution.R +++ b/tests/testthat/test-describe_distribution.R @@ -226,6 +226,6 @@ test_that("distribution_mode works as expected", { test_that("describe_distribution regex", { expect_equal( describe_distribution(mtcars, select = "pg", regex = TRUE), - describe_distribution(mtcars, select = "mpg")) + describe_distribution(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-find_columns.R b/tests/testthat/test-find_columns.R index ed802ee07..c36082166 100644 --- a/tests/testthat/test-find_columns.R +++ b/tests/testthat/test-find_columns.R @@ -118,6 +118,6 @@ test_that("find_columns from other functions", { test_that("find_columns regex", { expect_equal( find_columns(mtcars, select = "pg", regex = TRUE), - find_columns(mtcars, select = "mpg")) + find_columns(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-labelled_data.R b/tests/testthat/test-labelled_data.R index 2fe3176fe..b0f92c730 100644 --- a/tests/testthat/test-labelled_data.R +++ b/tests/testthat/test-labelled_data.R @@ -331,12 +331,12 @@ test_that("get_columns, labels preserved", { -# change_code ----------------------------------- +# recode_values ----------------------------------- -test_that("change_code, labels preserved", { +test_that("recode_values, labels preserved", { options(data_recode_pattern = NULL) data(efc) - x <- change_code(efc$c172code, recode = list(`0` = 1:2, `1` = 3)) + x <- recode_values(efc$c172code, recode = list(`0` = 1:2, `1` = 3)) expect_equal( attr(x, "label", exact = TRUE), attr(efc$c172code, "label", exact = TRUE), diff --git a/tests/testthat/test-normalize.R b/tests/testthat/test-normalize.R index c7bd9e8fd..a99e00ddf 100644 --- a/tests/testthat/test-normalize.R +++ b/tests/testthat/test-normalize.R @@ -177,6 +177,6 @@ test_that("normalize, factor (grouped data)", { test_that("normalize regex", { expect_equal( normalize(mtcars, select = "pg", regex = TRUE), - normalize(mtcars, select = "mpg")) + normalize(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-ranktransform.R b/tests/testthat/test-ranktransform.R index 94532cc4d..8fa31778a 100644 --- a/tests/testthat/test-ranktransform.R +++ b/tests/testthat/test-ranktransform.R @@ -113,6 +113,6 @@ test_that("ranktransform works with data frames containing NAs (grouped data)", test_that("ranktransform regex", { expect_equal( ranktransform(mtcars, select = "pg", regex = TRUE), - ranktransform(mtcars, select = "mpg")) + ranktransform(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-standardize-data.R b/tests/testthat/test-standardize-data.R index 64466faca..a52984a04 100644 --- a/tests/testthat/test-standardize-data.R +++ b/tests/testthat/test-standardize-data.R @@ -242,6 +242,6 @@ test_that("unstandardize does nothing with characters and factors", { test_that("standardize regex", { expect_equal( standardize(mtcars, select = "pg", regex = TRUE), - standardize(mtcars, select = "mpg")) + standardize(mtcars, select = "mpg") + ) }) - diff --git a/tests/testthat/test-format_text.R b/tests/testthat/test-text_format.R similarity index 100% rename from tests/testthat/test-format_text.R rename to tests/testthat/test-text_format.R diff --git a/tests/testthat/test-unnormalize.R b/tests/testthat/test-unnormalize.R index d04a5b819..f635feb63 100644 --- a/tests/testthat/test-unnormalize.R +++ b/tests/testthat/test-unnormalize.R @@ -39,6 +39,6 @@ test_that("unnormalize regex", { x <- normalize(mtcars, select = "mpg") expect_equal( unnormalize(x, select = "pg", regex = TRUE), - unnormalize(x, select = "mpg")) + unnormalize(x, select = "mpg") + ) }) -