I am having trouble joining 2 tibbles within a function using the curly curly ({{}}) syntax for the key variable.
The following code runs fine:
tab_across <- function(data, variable) {
master_tibble <- {{data}} %>% count({{variable}})
filtered_tibble <- {{data}} %>%
filter(l1_nar == "filter text") %>%
count({{variable}})
master_tibble <- master_tibble %>%
left_join(filtered_tibble, by = "my_variable")
print(master_tibble)
}
tab_across(my_data, my_variable)
However, if I change "my_variable" to either {{variable}} or "{{variable}}", the code fails, and I get the following two errors, respectively:
Error in standardise_join_by(by, x_names = x_names, y_names = y_names) :
object 'my_variable' not found
and
Error: Join columns must be present in data.
x Problem with `{{variable}}`.
Any help with this would be greatly appreciated.