0

I have a MySQL table that I am reading with the RMySQL package of R. I would like to be able to directly refer to the data frame stored in the table so I can seamlessly interact with it rather than having to execute RMySQL statement every time I want to do something. Is there a way to accomplish this? I tried:

data <- dbReadTable(conn = con, name = 'tablename')

For example, if I now want to check how many rows I have in this table I would run:

nrow(data)

Does this go through the database connection, or am I now storing the object "data" locally, defeating the whole purpose of using an external database?

bencrosier
  • 115
  • 6
  • How is this defeating the use of an external database? Could you please explain what you mean? As your question stands it does not make sense. – Lorenz Meyer Feb 17 '15 at 18:01
  • 1
    That downloads all the data into R. See the dplyr package for an alternative approach – hadley Feb 17 '15 at 18:12
  • Thank you @hadley. I am new at this, but I was certain I was already going down the wrong path :) – bencrosier Feb 17 '15 at 18:53

1 Answers1

1
data <- dbReadTable(conn = con, name = 'tablename')

This command downloads all the data into a local R dataframe (assuming you have enough RAM). Any operations with data from that point forward do not require the SQL connection.

JHowIX
  • 1,683
  • 1
  • 20
  • 38