rormdplyrrmysql

Is there a package for object-relational mapping in R?


(By object-relational mapping, I mean what is described here: Wikipedia: Object-relational mapping.)

Here is how I could imagine this work in R : a kind of "virtual data frame" is linked to a database, and returns the results of SQL queries when accessed. For instance, head(virtual_list) would actually return the results of (select * from mapped_table limit 5) on the mapped database.

I have found this post by John Myles White, but there seems to have been no progress in the last 3 years.

Is there a working package that implements this ?

If not,

  1. Would it be useful ?
  2. What would be the best way to implement it (S4 ?) ?

Solution

  • The very recent package dplyr is implementing this (amongst other amazing features).

    Here are illustrations from the examples of function src_mysql():

    # Connection basics ---------------------------------------------------------
    # To connect to a database first create a src:
    my_db <- src_mysql(host = "blah.com", user = "hadley",
      password = "pass")
    # Then reference a tbl within that src
    my_tbl <- tbl(my_db, "my_table")
    
    # Methods -------------------------------------------------------------------
    batting <- tbl(lahman_mysql(), "Batting")
    dim(batting)
    colnames(batting)
    head(batting)