peter dalgaard
2017-May-15 14:28 UTC
[Rd] 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)> 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
Martin Maechler
2017-May-15 15:04 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
>>>>> 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
peter dalgaard
2017-May-15 15:34 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
However, it doesn't look much of a hassle to fuse my suggestion into the current stopifnot: Basically, just use eval(as.name(paste0("..",i))) instead of ll[[i]] and base the initial calculation of n on match.call() rather than on list(...). -pd> On 15 May 2017, at 17:04 , Martin Maechler <maechler at stat.math.ethz.ch> wrote: > >>>>>> 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 > > > > > > > >-- 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
Hervé Pagès
2017-May-15 23:57 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
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
Possibly Parallel Threads
- stopifnot() does not stop at first non-TRUE argument
- stopifnot() does not stop at first non-TRUE argument
- stopifnot() does not stop at first non-TRUE argument
- stopifnot() does not stop at first non-TRUE argument
- stopifnot() does not stop at first non-TRUE argument