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

R语言 TypeInfo包 checkArgs()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-26 15:52:35 | 显示全部楼层 |阅读模式
checkArgs(TypeInfo)
checkArgs()所属R语言包:TypeInfo

                                        Validate the arguments in a call to a typed function.
                                         在调用一个类型的功能验证的论据。

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

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

TypeInfo uses checkArgs internally.
TypeInfo使用checkArgs内部。

This function is used to validate the arguments in a call to a function that has associated type information about the parameters.  The types for the parameters are currently given associated with the function via  an attribute "ParameterTypes". In the body of the function, one can call checkArgs and the specification is taken and used to compute whether the elements in the call are compatible with those in the signatures.
此功能是用来验证在一个有关联的有关参数的类型信息的功能调用的参数。目前的参数的类型与功能通过一个属性"ParameterTypes"。在身体的功能,可以调用checkArgs和规范,用来计算在通话的内容是否是签名兼容。

There are currently several ways to specify the signatures. One is as a list of  explicit parameter name - class name pair vectors given as c(paramName = className, paramName = className, ...). Alternatively, one can use an expression to perform a dynamic test. For example, one can test the length of an object, e.g. c(x = length(x) < 4, y = length(y) == length(x)). Each expression should return a logical value indicating whether the expected condition was satisfied. A third form of specifying signatures is given using class names for individual parameters and just matching the argument class to these names. This differs from the first form because the arguments are not checked simultaneoulsy, but rather one at a time. The test for a given argument is whether it is in the named vector of classes.
目前有几种方式来指定签名。其一是作为一个明确的参数名称的列表 - 类名称对c(paramName = className, paramName = className, ...)向量。另外,可以使用表达式进行动态测试。例如,一个可以测试对象的长度,例如: c(x = length(x) < 4, y = length(y) == length(x))。每个表达式应该返回一个逻辑值,指明是否满足预期的条件。一个指定签名的第三种形式是使用个别参数的类名和匹配参数类,这些名称。这不同于第一种形式,因为参数不simultaneoulsy检查,而是一次一个。对于一个给定的参数测试,无论是在类的命名向量。


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


checkArgs(f = sys.function(1), argNames, args = NULL, forceAll = FALSE,
          env = sys.frame(1), isMissing = logical(0))



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

参数:f
the function object. If this is missing, the function is taken as the function being called in the previous frame, i.e. the one that called checkArgs.  
函数对象。如果缺少,在上一帧被调用的函数功能,即那个叫checkArgs。


参数:argNames
a character vector giving the names of the arguments that are to be checked.
字符向量的论点是要检查的名称。


参数:args
a list of named argument values.
命名参数值列表。


参数:forceAll
a logical value. If this is TRUE, then we evaluate all of the arguments in the call frame of the function being evaluated whose arguments we are to check. If this is FALSE, This should be a three-level enum to represent evaluate as needed, evaluate all referenced in any of the signatures and evaluate all of the arguments now.  
一个逻辑值。如果这是TRUE,然后我们评估正在评估我们是来检查其参数的函数调用帧中的所有参数。如果这是FALSE,这应该是一个三级枚举来表示现在评估需要,评估所有引用任何签名,并评估所有的参数。


参数:env
the environment in which arguments are located.
在其中的论据所在的环境。


参数:isMissing
named logical vector indicating missing formal arguments; defined internally when consulting f of class function </table>
内部定义的命名逻辑向量表示缺少正式的参数;咨询f类function</表>


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

If the check succeeds in matching the arguments to the parameter types, the signature that matched is returned. Otherwise, an error is raised. If the signature is returned, this can be used to validate the return value in the context of that signature.
如果检查成功的参数类型匹配的参数,返回匹配的签名。否则,就会引发错误。如果返回签名,这可以用来验证在该签名的情况下返回值。

Note that if an instance of SimultaneousTypeSpecification-class is provided to this function, the TypedSignature-class elements are searched sequentially until a matching one is found. That matching signature is returned.  Therefore, the order the signatures are specified within the SimultaneousTypeSpecification-class object is important. This could change if we wanted. At present, it is up to the author to specify what they want to have happen. We could use the S4 signature matching technique when this is finalized and implemented in C code.
注意:如果一个实例SimultaneousTypeSpecification-class提供此功能,的TypedSignature-class的元素是顺序搜索,直到匹配一个被发现。返回的匹配签名。因此,签名内SimultaneousTypeSpecification-class对象中指定的是重要的。如果我们想,这可能会改变。目前,它是由作者指定他们想要的东西已经发生。我们可以使用S4的签名匹配技术,这是定稿,并在C代码实现。


作者(S)----------Author(s)----------


Duncan Temple Lang &lt;duncan@wald.ucdavis.edu&gt;



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

typeInfo
typeInfo


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


bob = function(x, y) {
        checkArgs()  # Completely unecessary as we don't specify type information.[完全不必要的,因为我们没有指定类型的信息。]
        "Finished"
      }

# a call generates a warning to say that there was no type information.[调用生成一个警告说,没有任何类型的信息。]
bob()

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-22 22:00 , Processed in 0.038441 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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