The left_join() function does not create columns, it adds columns from data frame to another data frame. Here is an example with data similar to yours.
library(dplyr)
tab <- data.frame(i = rep("T1", 5),
j = c("T1", "T10", "T11", "T12", "T2"),
var = c(291058, 8297, 3889, 17064, 12163), stringsAsFactors = FALSE)
tab
#> i j var
#> 1 T1 T1 291058
#> 2 T1 T10 8297
#> 3 T1 T11 3889
#> 4 T1 T12 17064
#> 5 T1 T2 12163
pt = data.frame(CODE = "T1", X = 2.34, Y = 48.86, stringsAsFactors = FALSE)
pt
#> CODE X Y
#> 1 T1 2.34 48.86
join <- left_join(tab, pt, by = c("j" = "CODE"))
join
#> i j var X Y
#> 1 T1 T1 291058 2.34 48.86
#> 2 T1 T10 8297 NA NA
#> 3 T1 T11 3889 NA NA
#> 4 T1 T12 17064 NA NA
#> 5 T1 T2 12163 NA NA
Created on 2019-12-29 by the reprex package (v0.3.0.9000)
Can you show how you want the data to look as a result of the function?
When I call my function I declared the variables as follows:
join<-my_function(tb,pt, origin = "i", id = "CODE",x="X",y="Y")
That's when I get the error message.
The issue is that c() doesn't play nicely with tidy evaluation so we just have to find another way to deliver the joining condition.
Since the by argument of the *_join functions actually takes a named character vector as the input, we can achieve this with setNames (or even set_names from purrr if you want to stay within the tidyverse).
Note: When using setNames or set_names, the order of the arguments is inverted from the way we normally pass them to by. So the y table's column needs to be specified first and the x table's second (as the argument to nm).
This gives the same result here but to me is more intuitive, because left_join() combines two data.frames.
I tried to figure out what do those two arguments mean: tab, pt ? Is it OK if I change it to DF1 and DF2 ?
@Andrzej I'm simply re-using the parameter names from the function given by the OP. You're right though that tab and pt are not very intuitive names and something like DF1, DF2 would be better.