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

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

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

                                        Classes Defined as the Union of Other Classes
                                         作为联盟的其他类定义的类

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

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

A class may be defined as the union of other classes; that is, as a virtual class defined as a superclass of several other classes. Class unions are useful in method signatures or as slots in other classes, when we want to allow one of several classes to be supplied.
A类可以定义为其他类别的工会,也就是说,作为一个虚拟类的其他几个类的超类定义。类工会是在方法签名,或在其他类中,插槽时,我们要允许几类需提供有用的。


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


setClassUnion(name, members, where)
isClassUnion(Class)



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

参数:name
the name for the new union class.  
新的联盟类的名称。


参数:members
the classes that should be members of this union.
类,应该是这个联盟的成员。


参数:where
where to save the new class definition; by default, the environment of the package in which the setClassUnion call appears, or the global environment if called outside of the source of a package.
保存新的类定义,默认情况下,包的环境中setClassUnion呼叫出现时,或者如果一个包的源以外称为全球环境。


参数:Class
the name or definition of a class.  
一类的名称或定义。


Details

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

The classes in members must be defined before creating the union.  However, members can be added later on to an existing union, as shown in the example below. Class unions can be members of other class unions.
members类建立工会之前,必须定义。然而,委员可后来补充现有的工会,在下面的例子所示。级工会可以是其他类工会成员。

Class unions are the only way to create a class that is extended by a class whose definition is sealed (for example, the basic datatypes or other classes defined in the base or methods package in R are sealed).  You cannot say setIs("function", "other") unless "other" is a class union.  In general, a setIs call of this form changes the definition of the first class mentioned (adding "other" to the list of superclasses contained in the definition of "function").
级工会是创建一个扩展类,一类,其定义是密封的(例如,研发基地或方法包中定义的基本数据类型或其他类是密封的)的唯一途径。你不能说setIs("function", "other")"other"除非是一类工会。在一般情况下,setIs呼吁改变这种形式的定义中提到的第一类(加入"other"的在"function"的定义所载的父列表)。

Class unions get around this by not modifying the first class definition, relying instead on storing information in the subclasses slot of the class union.  In order for this technique to work, the internal computations for expressions such as extends(class1, class2) work differently for class unions than for regular classes; specifically, they test whether any class is in common between the superclasses of class1 and the subclasses of class2.
级工会解决这个问题,没有修改第一类定义,而不是依靠信息存储在阶级联盟的子类插槽。为了使这项技术工作,如内部计算表达式extends(class1, class2)不同的工作比普通班级工会,特别是,他们测试是否有任何类class1超之间的共同点是class2子类。

The different behavior for class unions is made possible because the class definition object for class unions has itself a special class, "ClassUnionRepresentation", an extension of class classRepresentation.
级工会不同的行为是可能的,因为类定义的对象类工会本身就是一个特殊的类,"ClassUnionRepresentation"类classRepresentation扩展。


参考文献----------References----------

Software for Data Analysis: Programming with R Springer.  (For the R version.)
Programming with Data Springer (For the original S4 version.)

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


## a class for either numeric or logical data[#数字或逻辑数据类]
setClassUnion("maybeNumber", c("numeric", "logical"))

## use the union as the data part of another class[#使用另一个类的数据部分工会]
setClass("withId", representation("maybeNumber", id = "character"))

w1 <- new("withId", 1:10, id = "test 1")
w2 <- new("withId", sqrt(w1)%%1 < .01, id = "Perfect squares")

## add class "complex" to the union "maybeNumber"[#添加类“复杂的”联盟“maybeNumber”]
setIs("complex", "maybeNumber")

w3 <- new("withId", complex(real = 1:10, imaginary = sqrt(1:10)))

## a class union containing the existing class  union "OptionalFunction"[#包含现有类联盟“OptionalFunction类工会”]
setClassUnion("maybeCode",
    c("expression", "language", "OptionalFunction"))

is(quote(sqrt(1:10)), "maybeCode")  ## TRUE[#真]



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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-5 02:10 , Processed in 0.023610 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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