From spencer.graves@pdf.com  Tue Feb 18 02:45:03 2003
From: spencer.graves@pdf.com (Spencer Graves)
Date: Tue Feb 18 02:45:03 2003
Subject: [Rd] match.arg
References: <11025.1045351178@www67.gmx.net> <3E4ECF33.4050901@pdf.com>
Message-ID: <3E518FBB.2080405@pdf.com>

Hello:

	  I'm not on the "r-devel" list, but I just modified "match.arg" from R 
1.6.2 for Windows to accept a vector for "arg".

	  Is it appropriate that I send such things to this email address for 
consideration for inclusion in a future release?

	  I just compared this with "match.arg" in S-Plus 6.1 for Windows. 
There, I got the following:

 > match.arg(c("a","b"), c("aa", "bb"))
[1] "aa" "bb"

	  However, match.arg(c("a", "b")) in a test function with "default" = 
c("aa", "bb") returned only "a";  the following returns c("aa", "bb").

Thanks for all your hard work in developing this marvelous product.

Sincerely,
Spencer Graves

match.arg <-
function (arg, choices)
{
     if (missing(choices)) {
         formal.args <- formals(sys.function(sys.parent()))
         choices <- eval(formal.args[[deparse(substitute(arg))]])
     }
#	 cat("choices =", choices, "\n")
	 for(j in 1:length(arg)){
	    if (all(arg[j] == choices))
    	     arg[j] <- choices[1]
		 else{
		    i <- pmatch(arg[j], choices)
    		 if (is.na(i))
       		  stop(paste("ARG should be one of", paste(choices, collapse = 
", "),
          		   sep = " "))
		    if (length(i) > 1)
    		     stop("there is more than one match in match.arg")
	   	 arg[j] <- choices[i]
		}
	}
	arg
}



[Rd] match.arg
Spencer Graves