Skip to content
Advertisement

In R how to make a string of fields in to a SQL join

In R given a string like “fld1,fld2” how can I get something like “b.fld1=v.fld1 and b.fld2=v.fld2” for a SQL query. The string may have up to 10 distinct elements. This is for trying to build a join on the fly. b and v are the aliases for two tables. There willo only be two tables.

Advertisement

Answer

String interpolation with stringr::str_glue is a convenient way of achieving this:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement