Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 7, 2023
1 parent 14efec4 commit 5d6f454
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/recode_into.r
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ recode_into <- function(...,
missing_index <- is.na(index)
# make sure index has no missing values. when we have missing values in
# original expression, these are considered as "no match" and set to FALSE
# we handle NA value later and thus want to remove them from "index" now
index[is.na(index)] <- FALSE
# overwriting values? do more recode-patterns match the same case?
if (is.na(default)) {
Expand Down Expand Up @@ -182,6 +183,8 @@ recode_into <- function(...,
out[index] <- value
# set back missing values
if (any(missing_index) && !is.na(default) && preserve_na) {
# but only where we still have default values
# we don't want to overwrite already recoded values with NA
out[missing_index & out == default] <- NA
}
}
Expand Down

0 comments on commit 5d6f454

Please sign in to comment.