Skip to content
Prev 53476 / 63424 Next

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

I think Herv?'s idea was just that if switch can evaluate arguments selectively, so can stopifnot(). But switch() is .Primitive, so does it from C. 

I think it is almost a no-brainer to implement a sequential stopifnot if dropping to C code is allowed. In R it gets trickier, but how about this:

Stopifnot <- function(...)
{
  n <- length(match.call()) - 1
  for (i in 1:n)
  {
    nm <- as.name(paste0("..",i))
    if (!eval(nm)) stop("not all true")
  }
}
Stopifnot(2+2==4)
Stopifnot(2+2==5, print("Hey!!!") == "Hey!!!")
Stopifnot(2+2==4, print("Hey!!!") == "Hey!!!")
Stopifnot(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,F,T)

  
    

Thread (22 messages)

Hervé Pagès stopifnot() does not stop at first non-TRUE argument May 2 Peter Dalgaard stopifnot() does not stop at first non-TRUE argument May 3 Hervé Pagès stopifnot() does not stop at first non-TRUE argument May 3 Hervé Pagès stopifnot() does not stop at first non-TRUE argument May 3 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 15 Serguei Sokol stopifnot() does not stop at first non-TRUE argument May 15 Serguei Sokol stopifnot() does not stop at first non-TRUE argument May 15 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 15 Peter Dalgaard stopifnot() does not stop at first non-TRUE argument May 15 Serguei Sokol stopifnot() does not stop at first non-TRUE argument May 15 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 15 Peter Dalgaard stopifnot() does not stop at first non-TRUE argument May 15 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 15 Serguei Sokol stopifnot() does not stop at first non-TRUE argument May 15 Luke Tierney stopifnot() does not stop at first non-TRUE argument May 15 Hervé Pagès stopifnot() does not stop at first non-TRUE argument May 15 Hervé Pagès stopifnot() does not stop at first non-TRUE argument May 15 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 16 Serguei Sokol stopifnot() does not stop at first non-TRUE argument May 16 Luke Tierney stopifnot() does not stop at first non-TRUE argument May 16 Luke Tierney stopifnot() does not stop at first non-TRUE argument May 16 Martin Maechler stopifnot() does not stop at first non-TRUE argument May 16