Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Oct 21, 2022
1 parent 2c8763b commit 227003d
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions R/step-setnames.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ step_setnames <- function(x, old, new, in_place, rename_groups = FALSE) {
stopifnot(is_bool(in_place))
stopifnot(is_bool(rename_groups))

x_vars <- replace_setnames_na(x$vars)
old <- replace_setnames_na(old)
new <- replace_setnames_na(new)

if (is.integer(old)) {
locs <- old
} else {
locs <- vctrs::vec_match(old, x_vars)
locs <- vctrs::vec_match(old, x$vars)
}

name_changed <- x_vars[locs] != new
name_changed <- x$vars[locs] != new
old <- old[name_changed]
new <- new[name_changed]
locs <- locs[name_changed]
Expand All @@ -25,7 +21,7 @@ step_setnames <- function(x, old, new, in_place, rename_groups = FALSE) {
return(x)
}

new_vars <- x_vars
new_vars <- x$vars
new_vars[locs] <- new
out <- step_call(x,
"setnames",
Expand All @@ -41,11 +37,3 @@ step_setnames <- function(x, old, new, in_place, rename_groups = FALSE) {

out
}

# Replace character `NA` names with "NA"
replace_setnames_na <- function(x) {
if (is.character(x)) {
x <- vctrs::vec_assign(x, is.na(x), "NA")
}
x
}

0 comments on commit 227003d

Please sign in to comment.