Suharto Anggono Suharto Anggono
2017-May-16 16:37 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
switch(i, ...) extracts 'i'-th argument in '...'. It is like eval(as.name(paste0("..", i))) . Just mentioning other things: - For 'n', n <- nargs() can be used. - sys.call() can be used in place of match.call() . --------------------------->>>>> 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-16 16:59 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
> On 16 May 2017, at 18:37 , Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> wrote: > > switch(i, ...) > extracts 'i'-th argument in '...'. It is like > eval(as.name(paste0("..", i))) .Hey, that's pretty neat! -pd> > Just mentioning other things: > - For 'n', > n <- nargs() > can be used. > - sys.call() can be used in place of match.call() . > --------------------------- >>>>>> 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- 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-16 18:26 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
On 05/16/2017 09:59 AM, peter dalgaard wrote:> >> On 16 May 2017, at 18:37 , Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> wrote: >> >> switch(i, ...) >> extracts 'i'-th argument in '...'. It is like >> eval(as.name(paste0("..", i))) . > > Hey, that's pretty neat!Indeed! Seems like this topic is even more connected to switch() than I anticipated... H.> > -pd > >> >> Just mentioning other things: >> - For 'n', >> n <- nargs() >> can be used. >> - sys.call() can be used in place of match.call() . >> --------------------------- >>>>>>> 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 >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwIGaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=mLJLORFCunDiCafHllurGVVVHiMf85ExkM7B5DngfIk&s=helOsmplADBmY6Ct7r30onNuD8a6GKz6yuSgjPxljeU&e>-- 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
Martin Maechler
2017-May-18 08:03 UTC
[Rd] stopifnot() does not stop at first non-TRUE argument
>>>>> Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> >>>>> on Tue, 16 May 2017 16:37:45 +0000 writes:> switch(i, ...) > extracts 'i'-th argument in '...'. It is like > eval(as.name(paste0("..", i))) . Yes, that's neat. It is only almost the same: in the case of illegal 'i' the switch() version returns invisible(NULL) whereas the version we'd want should signal an error, typically the same error message as > t2 <- function(...) ..2 > t2(1) Error in t2(1) (from #1) : the ... list does not contain 2 elements > > Just mentioning other things: > - For 'n', > n <- nargs() > can be used. I know .. [in this case, where '...' is the only formal argument of the function] > - sys.call() can be used in place of match.call() . Hmm... in many cases, yes.... notably, as we do *not* want the argument names here, I think you are right. > --------------------------->>>>> 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 > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Seemingly Similar 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