From hpages at fredhutch.org  Tue May 16 01:57:05 2017
From: hpages at fredhutch.org (=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=)
Date: Mon, 15 May 2017 16:57:05 -0700
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: <8ed5a1c1-4f11-3305-17b1-3326b99e9480@fredhutch.org>

On 05/15/2017 07:28 AM, peter dalgaard wrote:
> I think Herv?'s idea was just that if switch can evaluate arguments selectively, so can stopifnot().

Yep.

Thanks,
H.

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

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



[Rd] stopifnot() does not stop at first non-TRUE argument
=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=