You can do this with rlang, actually I think quite easily since you're using tidyverse functions. From the documentation on the rlang injection operator !!:
All data-masking verbs in the tidyverse support injection operators out of the box. With base functions, you need to use inject() to enable !! .
Maybe a workflow like this:
left <- tibble::tibble(
id_1 = c("A", "B", "C"),
id_2 = c("D", "D", "E"),
left_val = c(1, 2, 3)
)
right <- tibble::tibble(
id_1 = c("A", "B", "C"),
id_2 = c("D", "E", "E"),
right_val = c(4, 5, 6)
)
join_vars <- c("id_1", "id_2")
dplyr::left_join(
left,
right,
dplyr::join_by(!!!join_vars)
)
#> # A tibble: 3 × 4
#> id_1 id_2 left_val right_val
#> <chr> <chr> <dbl> <dbl>
#> 1 A D 1 4
#> 2 B D 2 NA
#> 3 C E 3 6