representation(methods)
representation()所属R语言包:methods
Construct a Representation or a Prototype for a Class Definition
构造一个类定义表示或原型
译者:生物统计家园网 机器人LoveR
描述----------Description----------
In calls to setClass, these two functions construct, respectively, the representation and prototype arguments. They do various checks and handle special cases. You're encouraged to use them when defining classes that, for example, extend other classes as a data part or have multiple superclasses, or that combine extending a class and slots.
调用在setClass的,这两个函数的构造,分别representation和prototype参数。他们做各种检查和处理特殊情况。我们鼓励你定义的类,例如,扩展作为数据的一部分或其他类有多个父类,或扩展类和槽结合时使用它们。
用法----------Usage----------
representation(...)
prototype(...)
参数----------Arguments----------
参数:...
The call to representation takes arguments that are single character strings. Unnamed arguments are classes that a newly defined class extends; named arguments name the explicit slots in the new class, and specify what class each slot should have. In the call to prototype, if an unnamed argument is supplied, it unconditionally forms the basis for the prototype object. Remaining arguments are taken to correspond to slots of this object. It is an error to supply more than one unnamed argument.
代表的调用参数是单个字符的字符串。未命名的参数是一个新定义的类继承的类;命名参数命名新类中明确插槽,并指定每个插槽应该有什么类。 调用prototype在,如果一位不愿透露姓名的参数提供的,它无条件地构成为原型对象的基础上。其余的参数都采取对应到这个对象的插槽。这是一个错误,提供超过一个无名参数。
Details
详情----------Details----------
The representation function applies tests for the validity of the arguments. Each must specify the name of a class.
representation功能适用于测试参数的有效性。每个人都必须指定一个类的名称。
The classes named don't have to exist when representation is called, but if they do, then the function will check for any duplicate slot names introduced by each of the inherited classes.
类名为不存在的时候representation被称为,但如果他们这样做,那么函数将检查每个继承类中引入任何重复插槽名。
The arguments to prototype are usually named initial values for slots, plus an optional first argument that gives the object itself. The unnamed argument is typically useful if there is a data part to the definition (see the examples below).
的参数prototype通常命名为初始值槽,加上一个可选的第一个参数,使对象本身。未命名的参数通常是有用的,如果有一个数据部分的定义(见下面的例子)。
值----------Value----------
The value of representation is just the list of arguments, after these have been checked for validity.
值representation只是参数列表后,这些已被检查的有效性。
The value of prototype is the object to be used as the prototype. Slots will have been set consistently with the arguments, but the construction does not use the class definition to test validity of the contents (it hardly can, since the prototype object is usually supplied to create the definition).
prototype价值是将要使用的对象为原型。插槽将已设定一贯的论点,但施工不使用类的定义,测试的内容(它不可能,因为原型对象通常提供创建的定义)的有效性。
参考文献----------References----------
Software for Data Analysis: Programming with R Springer. (For the R version.)
Programming with Data Springer (For the original S4 version.)
参见----------See Also----------
setClass
setClass
举例----------Examples----------
## representation for a new class with a directly define slot "smooth"[#代表一个新的类直接定义槽“平稳”]
## which should be a "numeric" object, and extending class "track"[#这应该是一个“数字”的对象,扩展类的“轨道”]
representation("track", smooth ="numeric")
setClass("Character",representation("character"))
setClass("TypedCharacter",representation("Character",type="character"),
prototype(character(0),type="plain"))
ttt <- new("TypedCharacter", "foo", type = "character")
setClass("num1", representation(comment = "character"),
contains = "numeric",
prototype = prototype(pi, comment = "Start with pi"))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|