stdRefClass(methods)
stdRefClass()所属R语言包:methods
Class "envRefClass"
类“envRefClass”
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Support Class to Implement R Objects using Reference Semantics
支持类来实现R对象使用引用语义
注意:----------NOTE:----------
The software described here is an initial version. The eventual goal is to support reference-style classes with software in R itself or using inter-system interfaces. The current implementation (R version 2.12.0) is preliminary and subject to change, and currently includes only the R-only implementation. Developers are encouraged to experiment with the software, but the description here is more than usually subject to change.
这里描述的是该软件的最初版本。最终的目标是在研发自己的软件或使用系统间的接口,以支持引用样式类。目前的执引号况(R版本2.12.0)是初步的,如有变更,目前仅包含唯一的R-执行。鼓励开发人员与软件的实验,但这里的描述是比平时更可能会有所变更。
目的类----------Purpose of the Class----------
This class implements basic reference-style semantics for R objects. Objects normally do not come directly from this class, but from subclasses defined by a call to setRefClass. The documentation below is technical background describing the implementation, but applications should use the interface documented under setRefClass, in particular the \$ operator and field accessor functions as described there.
这个类实现了R对象的基本参考样式的语义。对象通常不来直接从这个类,但是从调用setRefClass由定义的子。下面的文档是描述执行的技术背景,但应用程序应该使用下setRefClass,尤其是的\$操作员和现场访问函数描述有记载的接口。
一个基本的参考类----------A Basic Reference Class----------
The design of reference classes for R divides those classes up according to the mechanism used for implementing references, fields, and class methods. Each version of this mechanism is defined by a basic reference class, which must implement a set of methods and provide some further information used by setRefClass.
R参考类的设计,根据实施的引用,字段和类方法中使用的机制来划分这些类。这一机制的每个版本定义一个基本的参考类,它必须执行一套方法,并提供一些进一步的信息setRefClass。
The required methods are for operators \$ and \$<- to get and set a field in an object, and for initialize to initialize objects.
所需的方法,为运营商\$和\$<-来获取和设置对象中的一个字段,initialize初始化对象。
To support these methods, the basic reference class needs to have some implementation mechanism to store and retrieve data from fields in the object. The mechanism needs to be consistent with reference semantics; that is, changes made to the contents of an object are global, seen by any code accessing that object, rather than only local to the function call where the change takes place. As described below, class envRefClass implements reference semantics through specialized use of environment objects. Other basic reference classes may use an interface to a language such as Java or C++ using reference semantics for classes.
为了支持这些方法的基本参考类需要有一定的执行机制来存储和检索从领域对象中的数据。该机制需要引用语义一致;也就是说,对象的内容所做的更改是全球性的,任何访问该对象,而不是只发生变化的函数调用本地代码看到。如下所述,类envRefClass实现通过专门的使用环境中的对象引用语义。其他基本的参考类,可以使用接口语言,如Java或C + +的类的引用语义。
Usually, the R user will be able to invoke class methods on the class, using the \$ operator. The basic reference class method for \$ needs to make this possible. Essentially, the operator must return an R function corresponding to the object and the class method name.
通常情况下,R用户将能够调用的类的类方法,使用\$运营商。基本参考\$类的方法需要做到这一点。从本质上讲,运营商必须返回一个R函数相应的对象和类的方法名称。
Class methods may include an implementation of data abstraction, in the sense that fields are accessed by “get” and “set” methods. The basic reference class provides this facility by setting the "fieldAccessorGenerator" slot in its definition to a function of one variable. This function will be called by setRefClass with the vector of field names as arguments. The generator function must return a list of defined accessor functions. An element corresponding to a get operation is invoked with no arguments and should extract the corresponding field; an element for a set operation will be invoked with a single argument, the value to be assigned to the field. The implementation needs to supply the object, since that is not an argument in the method invocation. The mechanism used currently by envRefClass is described below.
类方法可能包括数据抽象的实现,在该领域“get”和“集”的方法访问的意识。基本参考类提供该设施,通过设置一个变量的函数在其定义"fieldAccessorGenerator"插槽。此功能将被称为setRefClass字段名作为参数向量。发电机函数必须返回一个列表定义的访问函数。不带任何参数,调用相应的get操作元素应提取相应的领域;一套操作的元素将被调用的一个参数,被分配到外地的价值。执行需要提供的对象,因为这不是一个方法调用的参数。目前使用envRefClass机制描述如下。
支持类----------Support Classes----------
Two virtual classes are supplied to test for reference objects: is(x, "refClass") tests whether x comes from a class defined using the reference class mechanism described here; is(x, "refObject") tests whether the object has reference semantics generally, including the previous classes and also classes inheriting from the R types with reference semantics, such as "environment".
两个虚拟的类提供给测试参考对象:is(x, "refClass")测试是否x来自定义的类,使用这里描述的参考类机制;is(x, "refObject")测试对象是否具有引用语义,包括前类和类继承从引用语义的R类型,如"environment"。
Installed class methods are "classMethodDefinition" objects, with slots that identify the name of the function as a class method and the other class methods called from this method. The latter information is determined heuristically when the class is defined by using the codetools recommended package. This package must be installed when reference classes are defined, but is not needed in order to use existing reference classes.
安装类的方法是"classMethodDefinition"的对象,插槽,识别的功能作为一个类的方法,并从该方法的其他类调用的方法名称。后者的信息是确定的,试探性地使用codetools建议包定义类时。参考类定义时,必须安装这个包,但并不需要为了利用现有的引用类。
作者(S)----------Author(s)----------
John Chambers
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|