!! equivalent in dplyr 1.0.7

Hi All.
I'm developing some code for an environment that has dplyr 1.0.7 installed (and I can't upgrade that one).

I have a function that gets the variable column.to.use, and inside it has a bit of code that looks like this

get.geneEntrezIDs.dict.from.symbol <-
  function(symbol_tbl, column.to.use = 'SYMBOL') {
...
   GeneNameToSYMBOLandALIAS <- dplyr::inner_join(requestedSymbol_tbl,
                                  HsSymbolAliasEntrezID,
                                  by = join_by(!!column.to.use == "SYMBOL"))
}

That works great on my computer, which has dplyr 1.3.1. However, join_by is too new. I've tried replacing the code with

 GeneNameToSYMBOLandALIAS <- dplyr::inner_join(requestedSymbol_tbl,
                                   HsSymbolAliasEntrezID,
                                   by = c(!!column.to.use, "SYMBOL"))

But the !! seems to confuse dplyr 1.0.7. What's the equivalent to use an external variable in dplyr 1.0.7.
Again, if I could update this environment, I would do so. I have to find some other solution.

Thank you,

Uri David

library(dplyr)
library(rlang)

(a1 <- data.frame(
  a = 1,
  b = 2
))

(c3 <- data.frame(
  a = 1,
  c = 3
))

col_to_use <- "a"

#in modern dplyr 
left_join(a1,
  c3,
  by = join_by(!!col_to_use == "a")
)

# using rlang features with older dplyr (and modern)
left_join(a1,
          c3,
          by = unlist(list2(!!col_to_use := "a"))
)

# using base R , named objects with older dplyr (and modern)
myby <- "a"
names(myby) <- col_to_use
left_join(a1,
          c3,
          by = myby
)

Thank you.
Are you sure abut the rlang and older dplyr? It doesn't work for me and fials with the same error as before. But base R works, so thank you

I tested the rlang with the following package versions;

> packageVersion("dplyr")
[1] ‘1.0.7’
> packageVersion("rlang")
[1] ‘1.1.0’

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.