Skip to content

Commit

Permalink
Rename change_code() to recode_values() (#235)
Browse files Browse the repository at this point in the history
Closes #233

Co-authored-by: Daniel <[email protected]>
  • Loading branch information
IndrajeetPatil and strengejacke authored Aug 25, 2022
1 parent 6adeff4 commit a9668f6
Show file tree
Hide file tree
Showing 68 changed files with 462 additions and 403 deletions.
11 changes: 6 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions R/adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 16 additions & 12 deletions R/categorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions R/center.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions R/convert_na_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions R/convert_to_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions R/data_arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 6 additions & 5 deletions R/data_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion R/data_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions R/data_relocate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion R/data_remove.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
22 changes: 12 additions & 10 deletions R/data_rescale.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
22 changes: 12 additions & 10 deletions R/data_reverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
Loading

0 comments on commit a9668f6

Please sign in to comment.