StructureClasses(methods)
StructureClasses()所属R语言包:methods
Classes Corresponding to Basic Structures
类通讯基本结构
译者:生物统计家园网 机器人LoveR
描述----------Description----------
The virtual class structure and classes that extend it are formal classes analogous to S language structures such as arrays and time-series.
虚拟类structure和扩展它的类是类似S语言结构,如阵列和时间序列的正规类。
用法----------Usage----------
## The following class names can appear in method signatures,
## as the class in as() and is() expressions, and, except for
## the classes commented as VIRTUAL, in calls to new()
"matrix"
"array"
"ts"
"structure" ## VIRTUAL
从类的对象----------Objects from the Classes----------
Objects can be created by calls of the form new(Class, ...), where Class is the quoted name of the specific class (e.g., "matrix"), and the other arguments, if any, are interpreted as arguments to the corresponding function, e.g., to function matrix(). There is no particular advantage over calling those functions directly, unless you are writing software designed to work for multiple classes, perhaps with the class name and the arguments passed in.
可以通过电话的形式new(Class, ...),其中Class是引述的特定类的名称(例如,"matrix"),和其他参数,如果有的话,解释为创建对象相应的功能参数,如函数matrix()。有没有特别的优势超过直接调用这些函数,除非你正在编写的软件设计工作多个类,类的名称和传入的参数,也许
Objects created from the classes "matrix" and "array" are unusual, to put it mildly, and have been for some time. Although they may appear to be objects from these classes, they do not have the internal structure of either an S3 or S4 class object. In particular, they have no "class" attribute and are not recognized as objects with classes (that is, both is.object and isS4 will return FALSE for such objects). However, methods (both S4 and S3) can be defined for these pseudo-classes and new classes (both S4 and S3) can inherit from them.
从类"matrix"和"array"创建的对象是不寻常的,把它温和,已经有一段时间了。虽然他们可能会出现从这些类的对象,他们没有一个S3或S4类对象的内部结构。尤其是,他们有没有"class"属性,不确认为类的对象(即,既is.object和isS4将返回FALSE这样的对象)。然而,方法(S4和S3)可以被定义为这些伪类可以从他们身上继承的新类(S4和S3)。
That the objects still behave as if they came from the corresponding class (most of the time, anyway) results from special code recognizing such objects being built into the base code of R. For most purposes, treating the classes in the usual way will work, fortunately. One consequence of the special treatment is that these two classesmay be used as the data part of an S4 class; for example, you can get away with contains = "matrix" in a call to setGeneric to create an S4 class that is a subclass of "matrix". There is no guarantee that everything will work perfectly, but a number of classes have been written in this form successfully.
该对象仍然表现得好像他们从相应的类(大部分时间),反正从承认这样的对象被建成的河的基本代码,在大多数情况下,通常的方法治疗类的特殊代码的结果会工作幸运的。特殊处理的后果之一是作为一个S4级的数据部分使用,这两个classesmay;例如,你可以得到以contains = "matrix"在setGeneric创建S4类调用,是"matrix"的子类。有没有保证,一切都将完美的工作,但一类数量在这种形式已成功写入。
Note that a class containing "matrix" or "array" will have a .Data slot with that class. This is the only use of .Data other than as a pseudo-class indicating the type of the object. In this case the type of the object will be the type of the contained matrix or array. See Classes for a general discussion.
需要注意的是一类含有"matrix"或"array"将这个类有一个.Data插槽。这是唯一使用.Data比其他伪类表示的对象的类型。在这种情况下,将对象类型所包含的矩阵或数组类型。看到Classes进行了一般性讨论。
The class "ts" is basically an S3 class that has been registered with S4, using the setOldClass mechanism. Versions of R through 2.7.0 treated this class as a pure S4 class, which was in principal a good idea, but in practice did not allow subclasses to be defined and had other intrinsic problems. (For example, setting the "tsp" parameters as a slot often fails because the built-in implementation does not allow the slot to be temporarily inconsistent with the length of the data. Also, the S4 class prevented the correct specification of the S3 inheritance for class "mts".)
类"ts"基本上是已经注册的中S4中,使用setOldClass机制S3类。 2.7.0通过R版本作为一个纯粹的S4级,这是一个好主意主要处理这一类,但在实践中不容许被定义的子类,并有其他内在问题。 (例如,作为一个插槽设置的"tsp"的参数往往失败,因为内置在执行不允许插槽是暂时的数据长度不一致。此外,在S4级预防的正确规范S3的继承类"mts"。)
Time-series objects, in contrast to matrices and arrays, have a valid S3 class, "ts", registered using an S4-style definition (see the documentation for setOldClass in the examples section for an abbreviated listing of how this is done. The S3 inheritance of "mts" in package stats is also registered. These classes, as well as "matrix" and "array" should be valid in most examples as superclasses for new S4 class definitions.
时间序列对象,矩阵和数组相比,有一个有效的S3类,"ts",注册使用S4风格的定义(看到setOldClass在缩写上市的示例一节的文件如何做到这一点的S3继承"mts"包stats也这些类,以及"matrix"和父"array"应该在大多数的例子有效注册。新的S4类的定义。
All of these classes have special S4 methods for initialize that accept the same arguments as the basic generator functions, matrix, array, and ts, in so far as possible. The limitation is that a class that has more than one non-virtual superclass must accept objects from that superclass in the call to new; therefore, a such a class (what is called a “mixin” in some languages) uses the default method for initialize, with no special arguments.
所有这些类initialize接受基本的发电机功能相同的参数,matrix,array,ts,到目前为止,可能有特殊的S4方法。限制是有一个以上的非虚拟的超类,必须接受从该调用new在超类中的对象,因此,这样的一个类(什么叫做“混入”,在某些语言) initialize使用默认的方法,没有特殊的参数。
延伸----------Extends----------
The specific classes all extend class "structure", directly, and class "vector", by class "structure".
具体的类都继承"structure",直接和类类"vector"类"structure"。
方法----------Methods----------
coerce Methods are defined to coerce arbitrary objects to these classes, by calling the corresponding basic function, for example, as(x, "matrix") calls as.matrix(x). If strict = TRUE in the call to as(), the method goes on to delete all other slots and attributes other than the dim and dimnames.
定义要挟方法强迫任意对象,这些类通过调用相应的基本功能,例如,as(x, "matrix")称as.matrix(x)。如果strict = TRUE在as()调用,方法去删除所有其他插槽和属性比dim和dimnames。
Ops Group methods (see, e.g., S4groupGeneric) are defined for combinations of structures and vectors (including special cases for array and matrix), implementing the concept of vector structures as in the reference. Essentially, structures combined with vectors retain the structure as long as the resulting object has the same length. Structures combined with other structures remove the structure, since there is no automatic way to determine what should happen to the slots defining the structure.
OPS组的方法(例如,见S4groupGeneric)结构和向量(包括数组和矩阵的特殊情况下)的组合,实施作为参考矢量结构的概念,定义。从本质上讲,与向量相结合的结构保留的结构生成的对象具有相同的长度长。与其他结构相结合的结构,消除结构,因为没有自动的方法来确定应该发生什么定义结构的插槽。
Note that these methods will be activated when a package is loaded containing a class that inherits from any of the structure classes or class "vector".
请注意,这些方法将被激活,装包时,包含一个类,结构类或类"vector"继承。
参考文献----------References----------
Software for Data Analysis: Programming with R Springer. (For the R version.)
Programming with Data Springer (For the original S4 version.)
The New S Language. Wadsworth & Brooks/Cole (for the original vector structures).
参见----------See Also----------
Class nonStructure, which enforces the alternative model, in which all slots are dropped if any math transformation or operation is applied to an object from a class extending one of the basic classes.
的类nonStructure强制执行的替代模型,如果任何数学变换或操作应用延伸的基本类的类对象中所有插槽都将被丢弃。
举例----------Examples----------
showClass("structure")
## explore a bit :[#探讨一下:]
showClass("ts")
(ts0 <- new("ts"))
str(ts0)
showMethods("Ops") # six methods from these classes, but maybe many more[从这些类六种方法,但也许很多]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|