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

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

[复制链接]
发表于 2012-2-17 09:47:14 | 显示全部楼层 |阅读模式
slot(methods)
slot()所属R语言包:methods

                                        The Slots in an Object from a Formal Class
                                         从对象中的一个正式的类的插槽

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

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

These functions return or set information about the individual slots in an object.
这些函数返回或设置对象的个人插槽的信息。


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


object@name
object@name <- value

slot(object, name)
slot(object, name, check = TRUE) <- value
.hasSlot(object, name)

slotNames(x)
getSlots(x)



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

参数:object
An object from a formally defined class.
从正式定义的类的对象。


参数:name
The name of the slot. The operator takes a fixed name, which can be unquoted if it is syntactically a name in the language.  A slot name can be any non-empty string, but if the name is not made up of letters, numbers, and ., it needs to be quoted (by backticks or single or double quotes).  In the case of the slot function, name can be any expression that evaluates to a valid slot in the class definition. Generally, the only reason to use the functional form rather than the simpler operator is because the slot name has to be computed.  
插槽的名称。运营商需要一个固定的名称,可以加引号,如果它的语法是语言的名称。插槽名称可以是任何非空字符串,但如果名称是由字母,数字,和.,它需要被引用(反引号或单引号或双引号)。 slot功能的情况下,name可以是任何表达式,在类定义的有效插槽。一般来说,使用功能的形式,而不是简单的运营商的唯一原因是因为计算插槽名称。


参数:value
A new value for the named slot.  The value must be valid for this slot in this object's class.
一个新值命名插槽。该值必须是有效的这个对象的类的插槽。


参数:check
In the replacement version of slot, a flag.  If TRUE, check the assigned value for validity as the value of this slot.  User's coded should not set this to FALSE in normal use, since the resulting object can be invalid.  
在slot,一个标志的更换版本。如果TRUE,检查的有效性分配值作为这个槽的值。用户的编码,不应该设置FALSE在正常使用,因为由此产生的对象可以是无效的。


参数:x
either the name of a class (as character string), or a class definition.  If given an argument that is neither a character string nor a class definition, slotNames (only) uses class(x) instead.
无论是一个类的名称(如字符串),或一个类的定义。如果给定的参数既不是一个字符串,也不是一个类的定义,slotNames(只),使用class(x)代替。


Details

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

The definition of the class specifies all slots directly and indirectly defined for that class.  Each slot has a name and an associated class.  Extracting a slot returns an object from that class.  Setting a slot first coerces the value to the specified slot and then stores it.
类定义指定为该类定义的所有直接和间接的插槽。每个插槽都有一个名称和一个相关的类。提取槽返回这个类的一个对象。首先设置一个插槽胁迫到指定插槽的值,然后保存起来。

Unlike general attributes, slots are not partially matched, and asking for (or trying to set) a slot with an invalid name for that class generates an error.
不同于一般的属性,插槽部分匹配,和一个无效的名称,类的插槽(或设置)要求产生一个错误。

The @ extraction operator and slot function themselves do no checking against the class definition, simply matching the name in the object itself. The replacement forms do check (except for slot in the case check=FALSE).  So long as slots are set without cheating, the extracted slots will be valid.
@提取运算符slot函数本身就没有检查,对类的定义,只需匹配对象本身的名称。更换的形式做检查(除了slot在check=FALSE)。提取插槽插槽只要没有作弊,将是有效的。

Be aware that there are two ways to cheat, both to be avoided but with no guarantees.  The obvious way is to assign a slot with check=FALSE.  Also, slots in R are implemented as attributes, for the sake of some back compatibility.  The current implementation does not prevent attributes being assigned, via attr<-, and such assignments are not checked for legitimate slot names.
要知道,有两种方法作弊,既要避免的,但没有保证。显而易见的方法是用check=FALSE插槽分配。此外,在R槽实施作为属性,为了一些回兼容性。目前的执引号况并不妨碍被分配的属性,通过attr<-,这样的分配是不合法的插槽名称检查。


值----------Value----------

The "@" operator and the slot function extract or replace the formally defined slots for the object.
"@"运营商和slot功能提取或替换正式定义为对象的插槽。

Functions slotNames and getSlots return respectively the names of the slots and the classes associated with the slots in the specified class definition.  Except for its extended interpretation of x (above), slotNames(x) is just names(getSlots(x)).
功能slotNames和getSlots分别返回插槽,并在指定的类定义插槽类的名称。除x扩展解释slotNames(x)(以上),只是names(getSlots(x))。


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

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

参见----------See Also----------

@, Classes, Methods, getClass, names.
@,Classes,Methods,getClass,names。


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




setClass("track", representation(x="numeric", y="numeric"))
myTrack <- new("track", x = -4:4, y = exp(-4:4))
slot(myTrack, "x")
slot(myTrack, "y") <- log(slot(myTrack, "y"))
utils::str(myTrack)

getSlots("track") # or[或]
getSlots(getClass("track"))
slotNames(class(myTrack)) # is the same as[是一样的]
slotNames(myTrack)



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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 06:20 , Processed in 0.022905 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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