[Rd] stopifnot() does not stop at first non-TRUE argument

Hervé Pagès hpages at fredhutch.org
Wed May 3 02:50:12 CEST 2017


It's surprising that stopifnot() keeps evaluating its arguments after
it reaches the first one that is not TRUE:

   > stopifnot(3 == 5, as.integer(2^32), a <- 12)
   Error: 3 == 5 is not TRUE
   In addition: Warning message:
   In stopifnot(3 == 5, as.integer(2^32), a <- 12) :
     NAs introduced by coercion to integer range
   > a
   [1] 12

The details section in its man page actually suggests that it should
stop at the first non-TRUE argument:

   ‘stopifnot(A, B)’ is conceptually equivalent to

    { if(any(is.na(A)) || !all(A)) stop(...);
      if(any(is.na(B)) || !all(B)) stop(...) }


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: hpages at fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

More information about the R-devel mailing list