[R] match.arg: how to prevent users from not specifying a value

Youyi Fong yfong at fhcrc.org
Wed Aug 19 02:42:29 CEST 2015


Hello, I have a function that looks like

f=function( type=c("dummy,"A","B,"C"), ... ) {
    type<-match.arg(type)
    if (type=="dummy") stop("Please choose a type that is not dummy.")
    ...
}

I put a "dummy" in the list of choices as a mechanism to prevent users
from not specifying a value for "type" when calling the function. My
question is whether there is a better way to achieve it that does not
need "dummy".

Thanks,
Youyi



More information about the R-help mailing list