Read tables from MySQL databases into R

1.5k views Asked by At

I'm trying to read tables from my database with DBI package in R :

mydb = dbConnect(MySQL(), user='root', password='*******', dbname='powercurve', host='127.0.0.1')

dbReadTable(mydb,"3.4m140sco")

But apparently the tables name are not allowed in R because I'm getting the error :

Error in .local(conn, statement, ...) : 

could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3.4m140sco' at line 1

If in MySQL database I change the name of that table to something like table1, then I can read it in R easily.

Can somebody help me how could I read those tables in R, because obviously I can not change the names of all the tables.

1

There are 1 answers

0
Satie On BEST ANSWER

Can the backticks do the trick?

dbReadTable(mydb,"`3.4m140sco`")