[R] Testing for arguments in a function

Paul Johnson pauljohn32 at gmail.com
Fri Sep 30 23:28:54 CEST 2011

Just for the record, following Bill Dunlap's advice, I think this is
the best answer to the question as originally posed is.

myfun <- function(vec, i=stop("'i' must be supplied")){

> myfun(1:40,10)
[1] 10
> myfun(1:10)
Error in myfun(1:10) : 'i' must be supplied

Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

More information about the R-help mailing list