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

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

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

                                        Manage Implicit Versions of Generic Functions
                                         管理隐版本的通用功能

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

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

Create or access implicit generic functions, used to enforce consistent generic versions of functions that are not currently generic.  Function implicitGeneric() returns the implicit generic version, setGenericImplicit() turns a generic implicit, prohibitGeneric() prevents your function from being made generic, and registerImplicitGenerics() saves a set of implicit generic definitions in the cached table of the current session.
创建或访问隐含的通用功能,用于执行一致的仿制版本的功能,目前没有通用。功能implicitGeneric()返回隐式通用版本,setGenericImplicit()变成一个通用的含蓄,prohibitGeneric()防止从正在做的通用功能,registerImplicitGenerics()保存在隐含的通用定义本届会议的缓存表。


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


implicitGeneric(name, where, generic)
setGenericImplicit(name, where, restore = TRUE)
prohibitGeneric(name, where)
registerImplicitGenerics(what, where)



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

参数:name
Character string name of the function.
字符函数的字符串名称。


参数:where
Package or environment in which to register the implicit generics.  When using the functions from the top level of your own package source, this argument can usually be omitted (and should be).
注册隐含泛型包或环境。当从自己的包源的顶层使用的功能,通常可以省略这个参数(应该)。


参数:generic
Optionally, the generic function definition to be cached, but usually omitted.   See Details section.
可选,通用的函数定义缓存,但通常省略。见详图。


参数:restore
Should the non-generic version of the function be restored after the current.
应的非泛型版本的功能得到恢复后的电流。


参数:what
For registerImplicitGenerics(), Optional table of the implicit generics to register, but nearly always omitted.   See Details section.
registerImplicitGenerics(),隐含的仿制药注册的可选表,但几乎总是省略。见详图。


Details

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

Multiple packages may define methods for the same function, using the version of a function stored in one package.  All these methods should be marshaled and dispatched consistently when a user calls the function.  For consistency, the generic version of the function must have a unique definition (the same arguments allowed in methods signatures, the same values for optional slots such as the value class, and the same standard or non-standard definition of the function itself).
多个包可以定义为相同的功能的方法,使用存储在一个包中的一个函数的版本。所有这些方法都应该被封送处理,并派出一贯的,当用户调用的功能。通用版本的功能的一致性,必须有一个独特的定义(方法签名,值类,如可选插槽相同的价值观,相同的标准或非标准的函数本身的定义允许相同的参数)。

If the original function is already an S4 generic, there is no problem.  The implicit generic mechanism enforces consistency when the version in the package owning the function is not generic.  If a call to setGeneric() attempts to turn a function in another package into a generic, the mechanism compares the proposed new generic function to the implicit generic version of that function. If the two agree, all is well. If not, and if the function belongs to another package, then the new generic will not be associated with that package.  Instead, a warning is issued and a separate generic function is created, with its package slot set to the current package, not the one that owns the non-generic version of the function. The effect is that the new package can still define methods for this function, but it will not share the methods in other packages, since it is forcing a different definition of the generic function.
如果原有的功能已经是中S4中通用的,是没有问题的。隐式的通用机制实施的一致性,拥有功能包的版本是不通用的。如果调用一个setGeneric()试图打开另一个封装成一个通用的功能,机制比较拟议的新的通用函数该函数的隐式通用版本。如果两人都同意,一切都很好。如果没有,如果该函数属于另一个包,然后在新的通用将不会与该包相关联。相反,则会发出警告和包槽设置当前包,而不是一个拥有的非泛型版本的功能,创建一个单独的通用功能。其效果是,新方案仍然可以定义此功能的方法,但它不会分享其他包中的方法,因为它迫使一个泛型函数的定义不同。

The right way to proceed in nearly all cases is to call setGeneric("foo"), giving only the name of the function; this will automatically use the implicit generic version. If you don't like that version, the best solution is to convince the owner of the other package to agree with you and to insert code to define the non-default properties of the function (even if the owner does not want foo() to be a generic by default).
在几乎所有情况下正确的方式来进行调用的setGeneric("foo"),只给函数的名称,这将自动使用隐式的通用版本。如果你不喜欢这个版本,最好的办法是说服其他包的所有者同意你的看法,并插入代码来定义函数的非默认属性(即使所有者不希望<X >是一个默认的通用)。

For any function, the implicit generic form is a standard generic in which all formal arguments, except for ..., are allowed in the signature of methods. If that is the suitable generic for a function, no action is needed. If not, the best mechanism is to set up the generic in the code of the package owning the function, and to then call setGenericImplicit() to record the implicit generic and restore the non-generic version.  See the example.
对于任何函数,隐式的通用形式是一个标准的通用,除...外所有形式参数,在方法签名允许。如果是合适的通用函数,不需要进行任何操作。如果没有,最好的机制是建立在拥有该功能的包中的代码的通用,然后调用setGenericImplicit()记录隐式通用和恢复非泛型版本。见的例子。

Note that the package can define methods for the implicit generic as well; when the implicit generic is made a real generic, those methods will be included.
请注意该软件包可以定义为隐含的通用方法,以及时隐通用是一个真正的通用,这些方法将被包括在内。

Other than predefining  methods, the usual reason for having a non-default implicit generic is to provide a non-default signature, and the usual reason for that is to allow lazy evaluation of some arguments.  See the example.  All arguments in the signature of a generic function must be evaluated at the time the function needs to select a method.  (But those arguments can be missing, with or without a default expression being defined; you can always examine missing(x) even for arguments in the signature.)
其他比预定义的方法,通常的原因有一个非默认的隐式通用提供了一个非默认的签名,与通常的原因是一些论点,让懒惰的评价。见的例子。一个泛型函数的签名中的所有参数都必须在功能的实现需要时间来选择一种方法进行评估。 (但是这些参数可以是失踪,或没有被定义的默认表达式,你可以随时检查missing(x)甚至在签名的参数。)

If you want to completely prohibit anyone from turning your function into a generic, call prohibitGeneric().
如果你想完全禁止任何人变成一个通用的函数,调用prohibitGeneric()。


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

Function implicitGeneric() returns the implicit generic definition (and caches that definition the first time if it has to construct it).
功能implicitGeneric()返回隐含的通用定义(和缓存该定义的第一次,如果有建设)。

The other functions exist for their side effect and return nothing useful.
存在的其他功能,其副作用和回报没有什么用处。


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

setGeneric
setGeneric


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



### How we would make the function \link{with}() into a generic:[##我们将如何使函数\链接{}(成通用):]

## Since the second argument, 'expr' is used literally, we want[#以来的第二个参数,是expr用于从字面上,我们希望]
## with() to only have "data" in the signature.[#()只有在签名中的“数据”。]

## Note that 'methods'-internal code now has already extended  with()[#注意,现在“methods内部代码已经与(扩大)]
## to do the equivalent of the following[#做相当于以下]
## Not run: [#无法运行:]
setGeneric("with", signature = "data")
## Now we could predefine methods for "with" if we wanted to.[#现在我们可以预先定义的方法“与”如果我们想。]

## When ready, we store the generic as implicit, and restore the original[#准备就绪后,我们存储隐通用的,并恢复原有]
setGenericImplicit("with")

## (This example would only work if we "owned" function with(),[#(这个例子只会工作,如果我们的“国有”的功能()]
##  but it is in base.)[#但它是在基地)]
## End(Not run)[#结束(不运行)]

implicitGeneric("with")

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 21:17 , Processed in 0.042509 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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