I have the following chunk of code:
gap <- 1000
HCE <- HCE %>%
dplyr::mutate(ordered = gap * (as.numeric(outcome) - 1) original)
I want to dismbiguate, in the mutate directive, that gap refers to the variable, not to a "gap" column. How can I do so?
CodePudding user response:
The .data and .env pronouns make it explicit where to find objects when programming with data-masked functions.
HCE %>%
mutate(ordered = .env$gap * (as.numeric(outcome) - 1) original)
Or use the injection operator !!:
HCE %>%
mutate(ordered = !!gap * (as.numeric(outcome) - 1) original)
