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

Hello:

I found a way to break the "match.arg" function I sent a few hours ago. 
    The following works better, I believe.

Thanks again for your great work on the R project.
Spencer Graves
##########################
match.arg <-
function (arg = NULL, choices= NULL)
{
     if (is.null(choices)) {
         formal.args <- formals(sys.function(sys.parent()))
         choices <- eval(formal.args[[deparse(substitute(arg))]])
     }
#	 cat("choices =", choices, ";  arg =", arg, "\n")
	 if((length(arg)==length(choices)) && all(arg==choices))
			return(choices[1])
	 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' =", arg[j],
					   "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