Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Jul 27, 2023
1 parent a614b71 commit bcd9445
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/spq_mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ spq_mutate = function(.query, ..., .label = NA, .within_box = c(NA, NA), .within
variable_names = names(variables)

# when trying to overwrite a variable name ----
if (any(question_mark(variable_names) %in% .query[["vars"]][["name"]])) {

renaming_to_do = any(question_mark(variable_names) %in% .query[["vars"]][["name"]])
if (renaming_to_do) {
## rename in existing query object ----
to_rename = un_question_mark(
intersect(question_mark(variable_names), .query[["vars"]][["name"]])
)
Expand All @@ -28,6 +29,7 @@ spq_mutate = function(.query, ..., .label = NA, .within_box = c(NA, NA), .within
\(.query, x) spq_rename_var(.query, old = x, new = sprintf("%s0", x)),
.init = .query
)
## rename in current arguments ----
rename_in_defs = function(x, variables) {
gsub(question_mark_escape(x), question_mark(sprintf("%s0", x)), variables)
}
Expand All @@ -37,6 +39,7 @@ spq_mutate = function(.query, ..., .label = NA, .within_box = c(NA, NA), .within
.init = variables
)
variables = rlang::set_names(variables, variable_names)
## unselect the overwritten variable ----
.query <- spq_select(.query, !!!sprintf("-%s0", to_rename))
}

Expand Down

0 comments on commit bcd9445

Please sign in to comment.