I have a few .sql files which aggregate a number of tables/views in a SQL Database. I want to be able to direct R to a specific sql file and execute it and return the results in a dataframe.
Googling around it seems that I can only grab actual tables/views which are in the database or I have to rewrite the sql query and run that through the package RODBC.
In python this can be done with pd.read_sql_query
RODBC
or another package before you can execute SQL commands against a database. If the data exists within R, you can use the librarysqldf
to run SQL queries against in-memory data. – Sihunnsql <- paste(readLines("myfile.sql"), collapse = "\n")
. Nowsql
is an R variable holding the SQL string. – Leibowitz