2

我最近遇到了可能是 R 中的另一个 OO 范式。

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"

两个问题:

  • 这是否对应于此处未列出的新范例?或者这只是一种操纵例如 S4 课程的方式?
  • 如何查看 dbReadTable 方法的来源?
4

1 回答 1

3

与 S4 方法一样,只需getMethod()使用您有兴趣检查的方法的签名进行调用:

## 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"

然后在看到上面的内容之后,你可能想看看返回的代码:

sqliteReadTable
于 2013-11-12T20:57:58.103 回答