I am trying to build a pipe that it capable of handling various input types. I left_join to a master table that may have an identical column name. dplyr appends the matching column names with .x and .y in the joined table. I want rename the column that originated from the master table (.y) to its original name. The pipe must work for both input1 and input2 (as independent input). Currently my Rename step throws and error. I tried mutate() as well but gives a similar error.
> names(input1.df)
[1] "A"
> names(input2.df)
[1] "A" "B"
>names(MasterTable.df)
[1] "A" "B" "C" "D" "E"
joined.df <- input2.df %>%
dplyr::left_join(MasterTable.df, by=("A")) %>%
dplyr::rename(B = ifelse(B.y %in% names(.)) B.y, B) %>%
dplyr::select(A, B) %>%
dplyr::mutate(New_Column = ifelse(is.na(B), A, B))