我最近在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"
两个问题:
答案 0 :(得分: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