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

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

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

                                         Get or Test for the Definition of a Method
                                         获取或测试方法定义

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

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

Functions to look for a method corresponding to a given generic function and signature. The functions getMethod and selectMethod return the method; the functions existsMethod and hasMethod test for its existence.  In both cases the first function only gets direct definitions and the second uses inheritance.  In all cases, the search is in the generic function itself or in the package/environment specified by argument where.
寻找一种方法对应一个给定的通用功能和签名的函数。职能getMethod和selectMethod返回的方法;功能existsMethod和hasMethod测试它的存在。在这两种情况下的第一个函数只有直接定义和第二次使用继承。在所有情况下,搜索是在通用功能本身或在指定的包/环境参数where。

The function findMethod returns the package(s) in the search list (or in the packages specified by the where argument) that contain a method for this function and signature.
功能findMethod返回在搜索列表中的包(S)(或在包where参数指定的),包含此功能的方法和签名。


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


getMethod(f, signature=character(), where, optional = FALSE,
          mlist, fdef)

existsMethod(f, signature = character(), where)

findMethod(f, signature, where)

selectMethod(f, signature, optional = FALSE, useInherited =,
             mlist = , fdef = , verbose = , doCache = )

hasMethod(f, signature=character(), where)




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

参数:f
A  generic function or the character-string name of one.
一个泛型函数或一个字符的字符串名称。


参数:signature
the signature of classes to match to the arguments of f.  See the details below.  
类的签名匹配参数f。请参阅下面的详细信息。


参数:where
The position or environment in which to look for the method(s):  by default, the table of methods defined in the generic function itself is used.
在寻找的方法(S):默认情况下,使用泛型函数本身定义的方法表的位置或环境。


参数:optional
If the selection in  selectMethod does find a valid method an error is generated, unless this argument is TRUE.  In that case, the value returned is  NULL if no method matches.
如果选择在selectMethod没有找到一个有效的方法,则会产生一个错误,除非这种说法是TRUE。在这种情况下,返回的值是NULL如果没有匹配的方法。


参数:mlist, fdef, useInherited, verbose, doCache
Optional arguments  to  getMethod and selectMethod for internal use.  Avoid these: some will work as expected and others will not, and none of them is required for normal use of the functions.  
getMethod和selectMethod供内部使用的可选参数。避免这些:有些工作如预期,别人不会,他们都不是需要的功能的正常使用。


Details

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

The signature argument specifies classes, corresponding to formal arguments of the generic function; to be precise, to the signature slot of the generic function object. The argument may be a vector of strings identifying classes, and may be named or not.  Names, if supplied, match the names of those formal arguments included in the signature of the generic.  That signature is normally all the arguments except ....  However, generic functions can be specified with only a subset of the arguments permitted, or with the signature taking the arguments in a different order.
signature参数指定类,相应的泛型函数的形式参数,要精确,signature插槽的通用功能对象。参数可以识别类的字符串是一个向量,并可能被命名与否。名称,如果提供的,符合通用的签名中包括那些正式参数的名称。该签名通常是所有参数,除了6。然而,通用的功能,可以指定只有一部分的允许,或签名以不同的顺序论点的论据。

It's a good idea to name the arguments in the signature to avoid confusion, if you're dealing with a generic that does something special with its signature.   In any case, the elements of the signature are matched to the formal signature by the same rules used in matching arguments in function calls (see match.call).
这是一个好主意,在签名的命名参数,以避免混乱,如果你是一个通用的,其签字做了特殊处理。在任何情况下,签名的元素匹配的参数在函数调用中使用相同的规则相匹配的正式签署(见match.call)。

The strings in the signature may be class names, "missing" or "ANY".  See Methods for the meaning of these in method selection.  Arguments not supplied in the signature implicitly correspond to class "ANY"; in particular, giving an empty signature means to look for the default method.
在签名的字符串可能是类名,"missing"或"ANY"。看到这些方法的选择意义的方法。在签名中提供的参数隐含对应类"ANY";,尤其是给一个空的签名意味着寻找默认的方法。

A call to getMethod returns the method for a particular function and signature.  As with other get functions, argument where controls where the function looks (by default anywhere in the search list) and argument optional controls whether the function returns NULL or generates an error if the method is not found.  The search for the method makes no use of inheritance.
一个getMethod调用返回一个特定的功能和签名的方法。与其他get功能,参数where控制函数(默认情况下,在搜索列表中的任何地方)和函数是否返回optional或生成一个参数NULL控制如果没有发现错误的方法。搜索方法不使用继承。

The function selectMethod also looks for a method given the function and signature, but makes full use of the method dispatch mechanism; i.e., inherited methods and group generics are taken into account just as they would be in dispatching a method for the corresponding signature, with the one exception that conditional inheritance is not used.  Like getMethod, selectMethod returns NULL or generates an error if the method is not found, depending on the argument optional.
函数selectMethod看起来也为给定的功能和签名方法,但方法调度机制,充分利用,即继承的方法和组泛型考虑,只是因为他们将派遣一个方法相应的签名,有一个例外,有条件的继承不使用。像getMethod,selectMethod返回NULL或产生一个错误,如果没有找到方法,根据参数optional。

The functions existsMethod and hasMethod return TRUE or FALSE according to whether a method is found, the first corresponding to getMethod (no inheritance) and the second to selectMethod.
existsMethod和hasMethod回报TRUE或FALSE根据是否找到方法,相应的第一getMethod(继承)和第二的职能selectMethod。


值----------Value----------

The call to selectMethod or getMethod returns  the selected method, if one is found. (This class extends function, so you can use the result directly as a function if that is what you want.) Otherwise an error is thrown if optional is FALSE  and  NULL is returned if optional is TRUE.
呼叫selectMethod或getMethod返回选定的方法,如果找到一个。 (这个类延伸function,所以你可以使用功能作为直接的结果,如果这是你想要什么。“),否则会抛出错误,如果optional是FALSE和NULL 返回如果optional是TRUE的。

The returned method object is a MethodDefinition object, except that the default method for a primitive function is required to be the primitive itself. Note therefore that the only reliable test that the search failed is is.null().
返回的对象的方法是一个MethodDefinition对象,除了为原始功能的默认方法是必需的,是原始的本身。因此,请注意,搜索失败是唯一可靠的测试is.null()。


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

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

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

Methods for the details of method selection; GenericFunctions for other functions manipulating methods and generic function objects; MethodDefinition for the class that represents
Methods方法选择的详情; GenericFunctions等功能,操作方法和泛型函数对象; MethodDefinition类代表


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


setGeneric("testFun", function(x)standardGeneric("testFun"))
setMethod("testFun", "numeric", function(x)x+1)
hasMethod("testFun", "numeric")
## Not run: [1] TRUE[#无法运行:[1]真]
hasMethod("testFun", "integer") #inherited[遗传]
## Not run: [1] TRUE[#无法运行:[1]真]
existsMethod("testFun", "integer")
## Not run: [1] FALSE[#无法运行:[1]假]
hasMethod("testFun") # default method[默认的方法]
## Not run: [1] FALSE[#无法运行:[1]假]
hasMethod("testFun", "ANY")
## Not run: [1] FALSE[#无法运行:[1]假]


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 05:22 , Processed in 0.026522 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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