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

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

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

                                        Methods to Initialize New Objects from a Class
                                         初始化类的新对象的方法

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

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

The arguments to function new to create an object from a particular class can be interpreted specially for that class, by the definition of a method for function initialize for the class. This documentation describes some existing methods, and also outlines how to write new ones.
可以解释函数new从一个特定的类创建一个对象的参数,特别为这个类的方法定义,功能initialize类。本文档介绍了一些现有的方法,还概述了如何编写新的。


方法----------Methods----------

The default method for initialize takes either named or unnamed arguments.  Argument names must be the names of slots in this class definition, and the corresponding arguments must be valid objects for the slot (that is, have the same class as specified for the slot, or some superclass of that class).  If the object comes from a superclass, it is not coerced strictly, so normally it will retain its current class (specifically, as(object, Class, strict = FALSE)).
initialize需要,无论是有名或无名的参数的默认方法。参数名称必须是在这个类的定义插槽的名称,以及相应的参数必须是有效的对象(即有相同的类作为指定的插槽,或一些这一类的超类)插槽。如果从超对象,它不强制严格,所以通常将保留其当前类(特别是as(object, Class, strict = FALSE))。

Unnamed arguments must be objects of this class, of one of its superclasses, or one of its subclasses (from the class, from a class this class extends, or from a class that extends this class). If the object is from a superclass, this normally defines some of the slots in the object.  If the object is from a subclass, the new object is that argument, coerced to the current class.
未命名的参数必须是这个类的对象,其超,或它的一个子类(类,从这个类继承的类,或从一个类,扩展这个类)。如果对象是从超,这通常在对象定义一些插槽。如果是从一个子类的对象,新对象是这样的说法,裹挟到当前类。

Unnamed arguments are processed first, in the order they appear. Then named arguments are processed.  Therefore, explicit values for slots always override any values inferred from superclass or subclass arguments.
首先处理未命名的参数,在他们出现的顺序。然后命名参数处理。因此,明确插槽值总是覆盖从超类或子类参数推断出的任何值。

Objects of a class that extends traceable are used to implement debug tracing (see class traceable and trace).
一个类,扩展的对象traceable用来实现调试跟踪(见类溯源和trace的)。

The initialize method for these classes takes special arguments def, tracer, exit, at, print.  The first of these is the object to use as the original definition (e.g., a function).  The others correspond to the arguments to trace.
initialize这些类的方法需要特殊参数def, tracer, exit, at, print。其中第一项是使用原来的定义(例如,一个函数)的对象。其他对应的参数trace。

The initialize method for environments takes a named list of objects to be used to initialize the environment.  Subclasses of "environment" inherit an initialize method through ".environment", which has the additional effect of allocating a new environment.  If you define your own method for such a subclass, be sure either to call the existing method via callNextMethod or allocate an environment in your method, since environments are references and are not duplicated automatically.
initialize环境的方法被用来初始化环境命名的对象名单。子类"environment"继承".environment"initialize方法,其中有额外分配一个新的环境影响。如果你定义这样一个子类自己的方法,是确定调用现有的方法,通过callNextMethod或分配一个环境,在你的方法,因为环境是引用和自动不重复。

This is a method for internal use only. It takes an optional functionDef argument to provide a generic function with a signature slot to define the argument names.  See Methods for details.
这是一个仅供内部使用的方法。这需要一个可选的functionDef参数与signature插槽提供一个通用的函数来定义的参数名称。有关详情,请参阅方法。


编写初始化方法----------Writing Initialization Methods----------

Initialization methods provide a general mechanism corresponding to generator functions in other languages.
初始化方法提供了一种通用机制,相应的发生器功能在其他语言。

The arguments to initialize are .Object and .... Nearly always, initialize is called from new, not directly.  The .Object argument is then the prototype object from the class.
的参数initialize是.Object“......几乎总是,initialize从new,而不是直接调用。 .Object参数,然后从类的原型对象。

Two techniques are often appropriate for initialize methods: special argument names and callNextMethod.
这两种技术常常是适当的initialize方法:特殊的参数名称和callNextMethod。

You may want argument names that are more natural to your users than the (default) slot names.  These will be the formal arguments to your method definition, in addition to .Object (always) and ... (optionally).  For example, the method for class "traceable" documented above would be created by a call to setMethod of the form:
您可能要更自然比你的用户(默认)插槽名称的参数名称。这些方法定义的形式参数,除了.Object(总是)和... (可选)。例如,类的方法"traceable"记录由setMethod的形式调用,将创建:

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


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

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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