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

gunter.berton at gene.com gunter.berton at gene.com
Fri Aug 17 20:03:44 CEST 2007


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:

> sessionInfo()
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:

> x<- letters[1:3]
> y <- c('aa','bb')
> match.arg(x,y) ## error because several.ok = FALSE, but note warning
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
> match.arg(x,y, several.ok = TRUE) 
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.
> x <- letters[1:2]
> match.arg(x,y, several.ok = TRUE) 
[1] "aa" "bb"


Bert Gunter
Genentech Nonclinical Statistics



More information about the R-devel mailing list