match.arg(base)
match.arg()所属R语言包:base
Argument Verification Using Partial Matching
使用部分匹配的参数验证
译者:生物统计家园网 机器人LoveR
描述----------Description----------
match.arg matches arg against a table of candidate values as specified by choices, where NULL means to take the first one.
match.arg与arg对指定一个候选值表choices,其中NULL意味着采取的第一个。
用法----------Usage----------
match.arg(arg, choices, several.ok = FALSE)
参数----------Arguments----------
参数:arg
a character vector (of length one unless several.ok is TRUE) or NULL.
一个字符向量(长度several.ok除非是TRUE)或NULL。
参数:choices
a character vector of candidate values
一个候选值的特征向量
参数:several.ok
logical specifying if arg should be allowed to have more than one element.
逻辑指定arg如果应允许有一个以上的元素。
Details
详情----------Details----------
In the one-argument form match.arg(arg), the choices are obtained from a default setting for the formal argument arg of the function from which match.arg was called. (Since default argument matching will set arg to choices, this is allowed as an exception to the "length one unless several.ok is TRUE" rule, and returns the first element.)
在一个参数的形式match.arg(arg),选择默认设置取得正式的说法arg的功能match.arg被称为。 (由于默认参数匹配设置argchoices,这是允许的例外“的长度为一several.ok除非是TRUE规则,并返回第一个元素。)
Matching is done using pmatch, so arg may be abbreviated.
进行匹配使用pmatch,所以arg可能是缩写。
值----------Value----------
The unabbreviated version of the exact or unique partial match if there is one; otherwise, an error is signalled if several.ok is false, as per default. When several.ok is true and more than one element of arg has a match, all unabbreviated versions of matches are returned.
确切的或独特的部分匹配的缩写的版本,如果有一个,否则一个错误信号several.ok如果是假的,因为每默认。当several.ok是真实的和多个arg的元素匹配,匹配的所有缩写的版本返回。
参见----------See Also----------
pmatch, match.fun, match.call.
pmatch,match.fun,match.call。
举例----------Examples----------
require(stats)
## Extends the example for 'switch'[#扩展为开关的例子]
center <- function(x, type = c("mean", "median", "trimmed")) {
type <- match.arg(type)
switch(type,
mean = mean(x),
median = median(x),
trimmed = mean(x, trim = .1))
}
x <- rcauchy(10)
center(x, "t") # Works[作品]
center(x, "med") # Works[作品]
try(center(x, "m")) # Error[错误]
stopifnot(identical(center(x), center(x, "mean")),
identical(center(x, NULL), center(x, "mean")) )
## Allowing more than one match:[#允许多个匹配:]
match.arg(c("gauss", "rect", "ep"),
c("gaussian", "epanechnikov", "rectangular", "triangular"),
several.ok = TRUE)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|