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

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

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

                                         Test the Validity of an Object
                                         测试对象的有效性

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

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

The validity of object related to its class definition is tested.  If the object is valid, TRUE is returned; otherwise, either a vector of strings describing validity failures is returned, or an error is generated (according to whether test is TRUE).  Optionally, all slots in the object can also be validated.
object有关其类定义的有效性测试。如果对象是有效的,TRUE返回,否则,要么是向量描述的有效性失败的字符串返回,或产生一个错误(根据是否test是TRUE)。可选对象中的所有插槽也可以验证。

The function setValidity sets the validity method of a class (but more normally, this method will be supplied as the validity argument to setClass).  The method should be a function of one object that returns TRUE or a description of the non-validity.
功能setValidity设置方法(但更通常的是,这种方法将validity参数提供给setClass)一类的有效性。该方法应该是一个对象,返回TRUE或描述的非有效性的功能。


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


validObject(object, test = FALSE, complete = FALSE)

setValidity(Class, method, where = topenv(parent.frame()) )

getValidity(ClassDef)



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

参数:object
any object, but not much will happen unless the object's class has a formal definition.
任何物体,但没有太大的会发生,除非该对象的类有一个正式的定义。


参数:test
logical; if TRUE and validity fails, the function returns a vector of strings describing the problems.  If test is FALSE (the default) validity failure generates an error.
逻辑;如果TRUE和有效性失败,该函数返回一个字符串矢量描述的问题。 test如果是FALSE(默认)的有效性失败,产生错误。


参数:complete
logical; if TRUE, validity methods will be applied recursively to any of the slots that have such methods.
逻辑,如果TRUE,有效性的方法将递归应用到任何插槽,有这样的方法。


参数:Class
the name or class definition of the class whose validity method is to be set.
其有效性的方法的类的名称或类定义进行设置。


参数:ClassDef
a class definition object, as from getClassDef.
定义一个类对象,从getClassDef。


参数:method
a validity method;  that is, either NULL or a function of one argument (object).  Like validObject, the function should return TRUE if the object is valid, and one or more descriptive strings if any problems are found.  Unlike validObject, it should never generate an error.  
有效方法是,无论是NULL或一个参数(object)的功能。像validObject,函数应该返回TRUE如果对象是有效的,并描述一个或多个字符串,如果发现任何问题。 与validObject,它不应该产生一个错误。


参数:where
the modified class definition will be stored in this environment.
修改后的类定义将存储在这样的环境。


Details

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

Validity testing takes place "bottom up": Optionally, if complete=TRUE, the validity of the object's slots, if any, is tested.  Then, in all cases, for each of the classes that this class extends (the "superclasses"), the explicit validity method of that class is called, if one exists.  Finally, the validity method of object's class is called, if there is one.
有效性测试需要的地方“自下而上”:(可选),如果complete=TRUE,对象的插槽的有效性,如果有的话,进行测试。然后,在所有情况下,每一个类,这个类扩展(“父”),明确的有效性这一类的方法被称为,如果存在的话。最后,有效的方法object的类,如果有一个被称为。

Testing generally stops at the first stage of finding an error, except that all the slots will be examined even if a slot has failed its validity test.
测试一般停止在发现错误的第一阶段,所有插槽插槽,即使失败的有效性测试将检查的除外。

The standard validity test (with complete=FALSE) is applied when an object is created via new with any optional arguments (without the extra arguments the result is just the class prototype object).
通过complete=FALSE任何可选参数(无需额外的参数,结果仅仅是类的原型对象)创建一个对象时,应用标准的有效性测试(用new)。

An attempt is made to fix up the definition of a validity method if its argument is not object.
尝试进行修复的有效方法的定义,如果它的参数是不object。


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

validObject returns TRUE if the object is valid. Otherwise a vector of strings describing problems found, except that if test is FALSE, validity failure generates an error, with the corresponding strings in the error message.
validObject返回TRUE如果对象是有效的。否则字符串描述问题的向量,除了如果test是FALSE,有效性故障产生相应的错误消息字符串错误。


参考文献----------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; class classRepresentation.
setClass;类classRepresentation。


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


setClass("track",
          representation(x="numeric", y = "numeric"))
t1 <- new("track", x=1:10, y=sort(stats::rnorm(10)))
## A valid "track" object has the same number of x, y values[#一个有效的“轨道”的对象有相同数量的x,y值]
validTrackObject <- function(object) {
    if(length(object@x) == length(object@y)) TRUE
    else paste("Unequal x,y lengths: ", length(object@x), ", ",
               length(object@y), sep="")
}
## assign the function as the validity method for the class[#指定函数类的有效性方法]
setValidity("track", validTrackObject)
## t1 should be a valid "track" object[#T1应该是一个有效的“轨道”的对象]
validObject(t1)
## Now we do something bad[#现在我们做坏事]
t2 <- t1
t2@x <- 1:20
## This should generate an error[#这应该产生一个错误]
## Not run: try(validObject(t2))[#无法运行:(validObject(T2))]


setClass("trackCurve",
         representation("track", smooth = "numeric"))

## all superclass validity methods are used when validObject[#所有超有效的方法是使用时validObject]
## is called from initialize() with arguments, so this fails[#初始化(带参数),所以失败]
## Not run: trynew("trackCurve", t2)[#无法运行:trynew(“trackCurve”,T2)]


setClass("twoTrack", representation(tr1 = "track", tr2 ="track"))

## validity tests are not applied recursively by default,[#有效性测试不能递归应用,默认情况下,]
## so this object is created (invalidly)[#所以这个对象被创建(无效)]
tT  <- new("twoTrack", tr2 = t2)

## A stricter test detects the problem[#一个严格的测试检测到的问题]
## Not run: try(validObject(tT, complete = TRUE))[#无法运行:(validObject(TT,完整= TRUE时))]


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-25 03:55 , Processed in 0.023241 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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