match.arg.ext {RSAGA} | R Documentation |
Extended Argument Matching
Description
match.arg.ext
matches arg
against a set of candidate values as specified by choices
; it extends match.arg()
by allowing arg
to be a numeric identifier of the choices
.
Usage
match.arg.ext(
arg,
choices,
base = 1,
several.ok = FALSE,
numeric = FALSE,
ignore.case = FALSE
)
Arguments
arg |
a character string or numeric value |
choices |
a character vector of candidate values |
base |
numeric value, specifying the numeric index assigned to the first element of |
several.ok |
logical specifying if |
numeric |
logical specifying if the function should return the numerical index (counting from |
ignore.case |
logical specifying if the matching should be case sensitive |
Details
When choices
are missing, they are obtained from a default setting for the formal argument arg
of the function from which match.arg.ext
was called.
Matching is done using pmatch()
(indirectly through a call to match.arg()
, so arg
may be abbreviated.
If arg
is numeric, it may take values between base
and length(choices)+base-1
. base=1
will give standard 1-based R indices, base=0
will give indices counted from zero as used to identify SAGA modules in library RSAGA.
Value
If numeric
is false and arg
is a character string, the function returns the unabbreviated version of the unique partial match of arg
if there is one; otherwise, an error is signalled if several.ok
is false, as per default. When several.ok
is true and there is more than one match, all unabbreviated versions of matches are returned.
If numeric
is false but arg
is numeric, match.arg.ext
returns name of the match corresponding to this index, counting from base
; i.e. arg=base
corresponds to choices[1]
.
If numeric
is true, the function returns the numeric index(es) of the partial match of arg
, counted from base
to length(choices)+base-1
. If arg
is already numeric, the function only checks whether it falls into the valid range from arg
to length(choices)+base-1
and returns arg
.
Author(s)
Alexander Brenning
See Also
Examples
# Based on example from 'match.arg':
require(stats)
center <- function(x, type = c("mean", "median", "trimmed")) {
type <- match.arg.ext(type,base=0)
switch(type,
mean = mean(x),
median = median(x),
trimmed = mean(x, trim = .1))
}
x <- rcauchy(10)
center(x, "t") # Works
center(x, 2) # Same, for base=0
center(x, "med") # Works
center(x, 1) # Same, for base=0
try(center(x, "m")) # Error