Answer the question
In order to leave comments, you need to log in
String formatting in R?
Hello.
Faced with the task of generating sql code in R.
Let's say I need to make several substitutions in a text string.
In python, this example would look like this:
sql_params = {'col1_type':'cat','col1_date':'date'}
string_to_format = """
select * from
(select * from some_table where col1_type='{'col1_type'}' and something=2) x1
union
(select * from some_table where col1_type='{'col1_type'}' and col1_date=to_date('{col1_date}','YYYYMMDD')) x2
"""
full_query = string_to_format.format(**sql_params)
Answer the question
In order to leave comments, you need to log in
I'm not sure, but maybe there are simpler solutions to the problem itself?
there is a package sqldf
and there is a function sql
from the packagedplyr
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question