From maechler at stat.math.ethz.ch  Mon May 15 17:04:40 2017
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 15 May 2017 17:04:40 +0200
Subject: [Rd] stopifnot() does not stop at first non-TRUE argument
In-Reply-To: <703806C3-8EC7-46D7-BE92-46C61B1BDE13@gmail.com>
References: <64acdaeb-2857-9017-68c9-9da08e29a617@fredhutch.org>
 <E5DADF15-58C6-4F73-BC56-C6404896982F@gmail.com>
 <c2b3cb22-90bd-5372-e8b9-d1ea8b2ab828@fredhutch.org>
 <8945f7e4-99ce-53fa-46ee-cce64078a6a8@fredhutch.org>
 <22809.26921.473223.395550@stat.math.ethz.ch>
 <8fdb66b1-f785-ed55-6e40-a4ef8138e637@insa-toulouse.fr>
 <26bd9210-e40c-0967-7abb-5f724b09c034@insa-toulouse.fr>
 <22809.44830.153073.675527@stat.math.ethz.ch>
 <703806C3-8EC7-46D7-BE92-46C61B1BDE13@gmail.com>
Message-ID: <22809.50056.401373.410919@stat.math.ethz.ch>

>>>>> peter dalgaard <pdalgd at gmail.com>
>>>>>     on Mon, 15 May 2017 16:28:42 +0200 writes:

    > 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. 

if he just meant that, then "yes, of course" (but not so interesting).

    > 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:

Something like this, yes, that's close to what Serguei Sokol had proposed
(and of course I *do*  want to keep the current sophistication
 of stopifnot(), so this is really too simple)

    > 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)


    >> On 15 May 2017, at 15:37 , Martin Maechler <maechler at stat.math.ethz.ch> wrote:
    >> 
    >> I'm still curious about Herv?'s idea on using  switch()  for the
    >> issue.

    > -- 
    > Peter Dalgaard, Professor,
    > Center for Statistics, Copenhagen Business School
    > Solbjerg Plads 3, 2000 Frederiksberg, Denmark
    > Phone: (+45)38153501
    > Office: A 4.23
    > Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



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