找回密码
 注册
查看: 1614|回复: 0

R语言:S4groupGeneric()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 20:09:38 | 显示全部楼层 |阅读模式
S4groupGeneric(methods)
S4groupGeneric()所属R语言包:methods

                                        S4 Group Generic Functions
                                         S4组通用功能

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Methods can be defined for group generic functions.  Each group generic function has a number of member generic functions associated with it.
方法可以被定义为通用功能组。每个组的通用功能,有一些成员与它相关的通用功能。

Methods  defined for a group generic function cause the same method to be defined for each member of the group, but a method explicitly defined for a  member of the group takes precedence over a method defined, with the same signature, for the group generic.
定义为一组通用功能的方法会导致同样的方法被定义为每个组的成员,但接管组成员明确定义的方法定义的方法具有相同签名的组通用。

The functions shown in this documentation page all reside in the methods package, but the mechanism is available to any programmer, by calling setGroupGeneric (provided package methods is attached).
本文档中的页面显示的所有功能都在methods包,但机制是任何程序员通过调用setGroupGeneric(提供包methods附后)。


用法----------Usage----------


## S4 group generics:
Arith(e1, e2)
Compare(e1, e2)
Ops(e1, e2)
Logic(e1, e2)
Math(x)
Math2(x, digits)
Summary(x, ..., na.rm = FALSE)
Complex(z)



参数----------Arguments----------

参数:x, z, e1, e2
objects.
对象。


参数:digits
number of digits to be used in round or signif.
数位数要round或signif使用。


参数:...
further arguments passed to or from methods.
进一步的参数传递到或从方法。


参数:na.rm
logical: should missing values be removed?
逻辑:应被删除缺失值吗?


Details

详情----------Details----------

Methods can be defined for the group generic functions by calls to setMethod in the usual way. Note that the group generic functions should never be called directly – a suitable error message will result if they are.  When metadata for a group generic is loaded, the methods defined become methods for the members of the group, but only if no method has been specified directly for the member function for the same signature. The effect is that group generic definitions are selected before inherited methods but after directly specified methods.  For more on method selection, see Methods.
setMethod通常的方式调用方法可以被定义为通用功能组。注意组通用功能不应该直接调用 - 如果他们是一个合适的错误消息将导致。当一组通用的元数据被加载,定义的方法成为组成员的方法,但已被指定唯一的方法,如果没有直接为成员函数相同的签名。效果组通用的定义继承的方法之前,但选定后直接指定的方法。方法的选择上,看到Methods。

There are also S3 groups Math, Ops, Summary and Complex, see ?S3groupGeneric, with no corresponding R objects, but these are irrelevant for S4 group generic functions.
也有S3的群体Math,Ops,Summary和Complex,看到?S3groupGeneric,没有相应的R对象,但这些都是S4组通用无关功能。

The members of the group defined by a particular generic can be obtained by calling getGroupMembers. For the group generic functions currently defined in this package the members are as follows:
由一个特定的通用定义的组的成员可以通过调用getGroupMembers。目前在此包中定义的通用功能,该组的成员名单如下:




Arith "+", "-", "*", "^",
Arith"+","-","*","^"




Compare "==", ">", "<",
Compare"==",">","<"




Logic "&amp;", "|".
Logic"&amp;","|"。




Ops "Arith", "Compare", "Logic"
Ops"Arith","Compare","Logic"




Math "abs", "sign", "sqrt", "ceiling", "floor", "trunc", "cummax", "cummin", "cumprod", "cumsum", "log", "log10", "log2", "log1p", "acos", "acosh", "asin", "asinh", "atan", "atanh", "exp", "expm1", "cos", "cosh", "sin", "sinh", "tan", "tanh", "gamma", "lgamma", "digamma", "trigamma"
Math"abs","sign","sqrt","ceiling","floor","trunc","cummax",<X >,"cummin","cumprod","cumsum","log","log10","log2","log1p","acos" "acosh","asin","asinh","atan","atanh","exp","expm1","cos", "cosh","sin","sinh","tan","tanh","gamma","lgamma","digamma"




Math2 "round", "signif"
Math2"round","signif"




Summary "max", "min", "range",
Summary"max","min","range"




Complex "Arg", "Conj", "Im",
Complex"Arg","Conj","Im"

Note that Ops merely consists of three sub groups.
请注意,Ops仅仅三个子集团组成。

All the functions in these groups (other than the group generics themselves) are basic functions in R.  They are not by default S4 generic functions, and many of them are defined as primitives.  However, you can still define formal methods for them, both individually and via the group generics.  It all works more or less as you might expect, admittedly via a bit of trickery in the background. See Methods for details.
在这些团体的所有功能(其他比组泛型自己的),他们不是默认情况下,中S4中的通用功能,其中不少是原语定义在R的基本功能。但是,您仍然可以定义为他们的正式方法,单独和通过组泛型。这一切工作或多或少可以预料,承认在后台通过弄虚作假位。有关详情,请参阅方法。

Note that two members of the Math group, log and trunc, have ... as an extra formal argument. Since methods for Math will have only one formal argument, you must set a specific method for these functions in order to call them with the extra argument(s).
请注意,两个Math组成员,log和trunc,有...作为一个额外的正式说法。自方法Math将只能有一个正式的说法,你必须设置这些功能的具体方法,以便打电话给他们的额外的参数(S)。

For further details about group generic functions see section 10.5 of Software for Data Analysis.
有关组的进一步详细信息,泛型函数数据分析软件10.5节。


参考文献----------References----------

Software for Data Analysis: Programming with R Springer.  (For the R version.)
Programming with Data Springer (For the original S4 version).

参见----------See Also----------

The function callGeneric is nearly always relevant when writing a method for a group generic.  See the examples below and in section 10.5 of Software for Data Analysis.
功能callGeneric写为一组通用的方法时,几乎总是有关。数据分析,请参见下面的例子和软件10.5节。

See S3groupGeneric for S3 group generics.
看到S3groupGeneric S3组泛型。


举例----------Examples----------


setClass("testComplex", representation(zz = "complex"))
## method for whole group "Complex"[#整组的方法“情结”]
setMethod("Complex", "testComplex",
          function(z) c("groupMethod", callGeneric(z@zz)))
## exception for Arg() :[#异常精氨酸():]
setMethod("Arg", "testComplex",
          function(z) c("ArgMethod", Arg(z@zz)))
z1 <- 1+2i
z2 <- new("testComplex", zz = z1)
stopifnot(identical(Mod(z2), c("groupMethod", Mod(z1))))
stopifnot(identical(Arg(z2), c("ArgMethod", Arg(z1))))

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 15:21 , Processed in 0.028370 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表