[Rd] stopifnot

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Jun 3 18:14:15 CEST 2019

>>>>> Suharto Anggono Suharto Anggono 
>>>>>     on Thu, 30 May 2019 14:45:22 +0000 writes:
>>>>> Suharto Anggono Suharto Anggono 
>>>>>     on Thu, 30 May 2019 14:45:22 +0000 writes:

    > Here is a patch to function 'stopifnot' that adds 'evaluated' argument and makes 'exprs' argument in 'stopifnot' like 'exprs' argument in 'withAutoprint'.

    > --- stop.R	2019-05-30 14:01:15.282197286 +0000
    > +++ stop_new.R	2019-05-30 14:01:51.372187466 +0000


Thank you, Suharto.

I've looked at the patch and tested it a bit, and also (re)read
your April 15 remarks (cited below).  I now agree that my hacks to
enable dealing with "language objects" (typically class
'expression')  'exprs' has remained hackish and hence not
working in all cases,  and that it may be a better idea to add
a new logical argument (as in other functions) which has to be
"switched" and then leads somewhat simpler and more robust code.

OTOH, of course, this is an API change would typically not go into the R
3.6.x series ... and I have no idea if it would affect much more
than R's own tests/reg-tests-* ...

Even though the argument name 'evaluated' was chosen for
withAutoprint(), I don't find it a very good name anymore, and -
if the change should happen - would probably prefer something
like 'is.language' or 'expr.is.language' or similar..

Could we get any other readers' opinions ?


    > --------------------------------------------
    > On Mon, 15/4/19, Suharto Anggono Suharto Anggono <suharto_anggono using yahoo.com> wrote:

    > Subject: Re: [Rd] stopifnot
    > To: "Martin Maechler" <maechler using stat.math.ethz.ch>
    > Cc: r-devel using r-project.org
    > Date: Monday, 15 April, 2019, 2:56 AM
    > Also, in current definition of function 'stopifnot' in R 3.6.0 beta or R devel, for 'cl' if 'exprs' is specified, there a case with comment "the *name* of an expression". The intent is allowing
    > stopifnot(exprs = ee) ,
    > where variable 'ee' holds an expression object, to work on the expression object.

    > It is not quite right to use eval(exprs) . It fails when 'stopifnot' is called inside a function, like
    > f <- function(ee) stopifnot(exprs = ee)
    > f(expression())

    > But, how about local=FALSE case? Should the following work?
    > f <- function(ee) stopifnot(exprs = ee, local = FALSE)
    > f(expression())

    > But, why bother making it work, while it is undocumented that 'exprs' argument in 'stopifnot' can be an expression? Well, yes, expectation may be set from the name "exprs" itself or from argument 'exprs' in function 'source' or 'withAutoprint'. Function 'withAutoprint' may be the closest match.

    > Function 'withAutoprint' has 'evaluated' argument that controls whether work is on value of  'exprs' or on 'exprs' as given. I like the approach.

More information about the R-devel mailing list