I have a large .sql file, created as a backup from a MySQL database (containing several tables), and I would like to search elements within it from R.
Ideally, there would be a read.sql function that would turn the tables into some R list with data.frames in it. Is there something that comes close? If not, can RSQLite or RMySQL help? (going through the reference manuals, I don't see a simple function for what I described)
No can do, boss. For R to interpret your MySQL database file, it would have to do a large part of what the DBMS itself does. That's a tall order, infeasible in the general case.
Would this return what you seek (which I think upon review you will admit is not yet particularly well described):
require(RMySQL)
drv <- dbDriver("MySQL")
con <- dbConnect(drv)
dbListTables(con)
# Or
names(dbGetInfo(drv))
If these are just source code than all you would need is readLines. If you are looking for an R-engine that can take SQL code and produce useful results then the sqldf package may provide some help. It parses SQL code embedded in quoted strings and applies it either to dataframe objects in memory or to disk-resident tables (or both). Its default driver for disk files is SQLite but other drivers can be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With