Skip to content
Prev 25911 / 63421 Next

match.arg bug or documentation error (PR#9859)

There is either a bug or undocumented feature (afaics) in match.arg that
requires the length of  the arg argument to be no longer than the length of
the choices argument even when several.ok is TRUE. Here is a reproducible
example:

first:
R version 2.5.0 Patched (2007-04-26 r41320) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "stats"     "graphics"  "grid"      "grDevices" "tcltk"     "utils"
"methods"   "base"     


## Now the example:
message.
Error in match.arg(x, y) : 'arg' should be one of aa, bb
In addition: Warning message:
longer object length
        is not a multiple of shorter object length in: arg == choices 

## So set several.ok=TRUE ... but there is still an error
Error in match.arg(x, y, several.ok = TRUE) : 
        'arg' should be one of aa, bb

## However, if x is of length 2, all is OK.
[1] "aa" "bb"


Bert Gunter
Genentech Nonclinical Statistics