I've the following dataframe,
df <- tibble(x = c(2, 3, 4)) %>%
mutate(`1` = 99, `2` = 88, `3` = 77, `4` = 66, `5` = 55)
column x holds the column names which needs to be manipulated, the value in that column has to be replaced with the sum of values in columns x-1, x and x+1. For example, for the first row where x is 2, value in column 2 has to be replaced with (99+88+77) = 264.
I tried using double curly brackets({{}}) and :=, like below,
df %>%
mutate("{{x}}" := {{x-1}} + {{x}} + {{x+1}})
but I'm getting the following error,
Error in local_error_context(dots = dots, .index = i, mask = mask) : promise already under evaluation: recursive default argument reference or earlier problems?
Then I tried accessing the column using cur_column() inside across() like below,
df %>%
mutate(across(-x, ~if_else(x == cur_column(), {{cur_column()}}, .x)))
and I'm getting the same error as above, I think I may be using the curly operator incorrectly, can someone help, please?