2

I recently ran across what may be yet another OO paradigm in R.

library(RSQLite)
> dbReadTable
standardGeneric for "dbReadTable" defined from package "DBI"
  defined with value class: "data.frame"

function (conn, name, ...) 
.valueClassTest(standardGeneric("dbReadTable"), "data.frame", 
    "dbReadTable")
<environment: 0x1d252198>
Methods may be defined for arguments: conn, name
Use  showMethods("dbReadTable")  for currently available ones.
> showMethods('dbReadTable')
Function: dbReadTable (package DBI)
conn="SQLiteConnection", name="character"

Two questions:

  • Does this correspond to a new paradigm not listed here? Or is this just a way of manipulating e.g. S4 classes?
  • How do I see the source for dbReadTable's methods?
Community
  • 1
  • 1
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235

1 Answers1

3

As usual for S4 methods, just call getMethod() with the signature of the method you're interested in examining:

## Use showMethods to view signatures of dbReadTable's methods
showMethods('dbReadTable')
# Function: dbReadTable (package DBI)
# conn="SQLiteConnection", name="character"

## getMethod's 2nd argument is a character vector containing method's signature 
getMethod("dbReadTable", c("SQLiteConnection", "character"))
# Method Definition:
# 
# function (conn, name, ...) 
# sqliteReadTable(conn, name, ...)
# <environment: namespace:RSQLite>
# 
# Signatures:
#         conn               name       
# target  "SQLiteConnection" "character"
# defined "SQLiteConnection" "character"

And then after seeing the above, you'll probably want to have a look a the code returned by:

sqliteReadTable
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • So it's S4 then. I was confused by the `.valueClassTest` from the RMethodUtils package. – Ari B. Friedman Nov 12 '13 at 21:31
  • 1
    @AriB.Friedman -- FYI, I believe that `.valueClassTest()` call is a bit of housekeeping code generated by the **methods** package when you use `setClass()`'s `valueClass` argument to specify an expected return value for the class you are setting up. – Josh O'Brien Nov 12 '13 at 22:42
  • @JoshOBrien You're right. See https://github.com/rstats-db/RSQLite/blob/master/R/SQLite.R#L196 – Ari B. Friedman Nov 13 '13 at 16:27