From gunter.berton at gene.com  Fri Aug 17 20:03:44 2007
From: gunter.berton at gene.com (gunter.berton at gene.com)
Date: Fri, 17 Aug 2007 20:03:44 +0200 (CEST)
Subject: [Rd] match.arg bug or documentation error (PR#9859)
Message-ID: <20070817180344.D62D766884@slim.kubism.ku.dk>


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



[Rd] match.arg bug or documentation error (PR#9859)
gunter.berton at gene.com