Hi Mike,
On 07/22/2015 04:13 PM, Michael Love wrote:
it's slightly annoying to write
foo <- function(x) {
if ( ! is.numeric(x) ) stop("x should be numeric")
if ( ! length(x) == 2 ) stop("x should be length 2")
c(x[2], x[1])
}
That's a little bit kind of what stopifnot() is for:
stopifnot(is.numeric(x) && length(x) == 2)
The error message you get is not perfect English but is very concise:
> foo(letters)
Error: is.numeric(x) && length(x) == 2 is not TRUE
H.
i wonder if we could have some core functions that test the class and
the length in one and give the appropriate stop message.
maybe this exists already
-Mike
_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpa...@fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel