Suppose I have this tibble with an arbitrary number of variable pairs x and x_var, y and y_var, etc.
dt <- tibble(x = 1:3,
y = 2:4,
z = 3:5,
x_var = rep(0.1, 3),
y_var = rep(0.2, 3),
z_var = rep(0.3, 3))
I was attempting to calculate x + x_var, y + y_var, etc all in one go, using mutate-across.
I tried
tb %>%
mutate(across(.cols = all_of(c("x", "y", "z")),
.names = "{col}_sum",
function(x) x + !!rlang::sym(paste0(cur_column(), "_var"))))
but this does not seem to work. I do not want to hard-code variable names and see that it can be done via pivoting, however I'm curious if mutate-across will do the trick somehow.