methods
位於 utils
包(package)。 說明
列出 S3 和 S4 通用函數的所有可用方法,或 S3 或 S4 類的所有方法。
用法
methods(generic.function, class, all.names = FALSE, dropPath = FALSE)
.S3methods(generic.function, class, envir = parent.frame(),
all.names = FALSE, dropPath = FALSE)
## S3 method for class 'MethodsFunction'
format(x, byclass = attr(x, "byclass"), ...)
## S3 method for class 'MethodsFunction'
print(x, byclass = attr(x, "byclass"), ...)
參數
generic.function |
泛型函數,或命名泛型函數的字符串。 |
class |
命名類的符號或字符串:僅在未提供 |
envir |
當泛型函數作為字符串傳遞時,在其中查找泛型函數的定義的環境。 |
all.names |
a |
dropPath |
a |
x |
通常的結果是 |
byclass |
可選的 |
... |
傳入和傳出方法的潛在進一步參數;目前未使用。 |
細節
methods()
查找與 generic.function
或 class
參數關聯的 S3 和 S4 方法。找到的方法是所有加載的命名空間通過注冊提供的方法,請參閱UseMethod
;通常,這包括當前 search()
路徑上的所有包。 .S3methods()
僅查找 S3 方法,.S4methods()
僅查找 S4 方法。
當使用 generic.function
參數調用時,"byclass"
屬性(請參閱詳細信息)為 FALSE
,並且 print
方法默認顯示 S3 和 S4 方法的簽名(全名)。 S3 方法通過將通用函數和類粘貼在一起來打印,並用“.”分隔,如 generic.class
。如果方法定義不是從定義該方法的包命名空間導出的,則 S3 方法名稱後跟星號 *
。 S4 方法簽名打印為 generic,class-method
; S4 允許多次調度,因此簽名 generic,A,B-method
中可能有多個類。
當使用 class
參數調用時,"byclass"
是 TRUE
,並且 print
方法默認顯示與類 generic
關聯的泛型函數的名稱。
所有函數的源代碼均可用。對於從命名空間導出的 S3 函數,請在命令行中輸入方法 generic.class
。對於未從命名空間導出的 S3 函數,請參閱 getAnywhere
或 getS3method
。對於 S4 方法,請參閱 getMethod
。
除了每種通用方法之外,還提供每種方法的幫助。對於交互式幫助,請使用文檔快捷方式 ?
以及通用名稱和製表符完成 ?"generic<tab>"
來選擇需要幫助的方法。
列出的 S3 函數是那些名稱類似於方法的函數,但實際上可能不是方法(代碼中會丟棄已知的異常)。
值
類 "MethodsFunction"
的對象,具有 "byclass"
和 "info"
屬性的方法名稱的字符向量。 "byclass"
屬性是 logical
,指示結果是否是通過定義的參數 class
獲得的。 "info"
屬性是一個包含列的 DataFrame :
- 通用的
-
character
泛型名稱向量。 - 可見的
-
logical(),方法“visible”是給用戶的嗎?當為 true 時,它通常從定義它的包的命名空間導出,並且包被
attach()
編輯到search()
路徑。 - 是S4
-
logical(),當該方法是 S4 方法時為 true。
- 從
-
a
factor
,找到該方法的位置或包名稱。
注意
最初的 methods
函數由 Martin Maechler 編寫。
例子
methods(class = "MethodsFunction") # format and print
require(stats)
methods(summary)
methods(class = "aov") # S3 class
## The same, with more details and more difficult to read:
print(methods(class = "aov"), byclass=FALSE)
methods("[[") # uses C-internal dispatching
methods("$")
methods("$<-") # replacement function
methods("+") # binary operator
methods("Math") # group generic
require(graphics)
methods(axis) # looks like a generic, but is not
mf <- methods(format) # quite a few; ... the last few :
tail(cbind(meth = format(mf)))
if(require(Matrix, quietly = TRUE)) {
print(methods(class = "Matrix")) # S4 class
m <- methods(dim) # S3 and S4 methods
print(m)
print(attr(m, "info")) # more extensive information
## --> help(showMethods) for related examples
}
參考
Chambers, J. M. (1992) Classes and methods: object-oriented programming in S. Appendix A of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
也可以看看
對於 S4,getMethod
、showMethods
、Introduction 或 Methods_Details
。
相關用法
- R menu 菜單交互函數
- R memory.size 內存分配報告
- R mirrorAdmin 管理存儲庫鏡像
- R make.socket 創建套接字連接
- R maintainer 顯示包維護者
- R make.packages.html 更新 HTML 包列表
- R modifyList 遞歸修改列表的元素
- R select.list 從列表中選擇項目
- R COMPILE 編譯用於 R 的文件
- R readRegistry 讀取 Windows 注冊表配置單元
- R browseVignettes 在 HTML 瀏覽器中列出暈影
- R hasName 檢查姓名
- R nsl 按主機名查找 IP 地址
- R edit 調用文本編輯器
- R create.post 準備電子郵件和帖子的輔助函數
- R hsearch-utils 幫助搜索實用程序
- R download.packages 從類似 CRAN 的存儲庫下載軟件包
- R DLL.version MS Windows 上的 DLL 版本信息
- R ls.str 列表對象及其結構
- R Rscript R 前端腳本
- R bug.report 發送錯誤報告
- R PkgUtils 用於構建和檢查附加包的實用程序
- R cite 引用參考書目條目
- R SweaveSyntConv 轉換 Sweave 語法
- R RSiteSearch 搜索文檔中的關鍵詞或短語
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 List Methods for S3 Generic Functions or Classes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。