“read.sql” function in R: Using R as an SQL browser?

后端 未结 3 1223
感动是毒
感动是毒 2021-01-14 10:28

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

3条回答
  •  我在风中等你
    2021-01-14 11:04

    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.

提交回复
热议问题