From deepayan.sarkar at gmail.com  Wed Aug 21 10:26:20 2013
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Wed, 21 Aug 2013 13:56:20 +0530
Subject: [Rd] Extending suggestion for stopifnot
In-Reply-To: <CAPr7RtWxF=Vh3OSpZEonKpLKnbDNnHT2X3dvAXVzeqdcnB2_CA@mail.gmail.com>
References: <CAPr7RtX3b5XBzgn1XT3nPcvX71G=W1CpK=tK1T3zz4zWW=pQNQ@mail.gmail.com>
	<CA+hbrhVcih5+u1hV5c2c_+HC6UJ6BzpdwmP4VWuuU=gdNmkz1Q@mail.gmail.com>
	<13664C4E-7ACE-410E-A0EE-6D07D5E590BD@muxspace.com>
	<CAPr7RtWxF=Vh3OSpZEonKpLKnbDNnHT2X3dvAXVzeqdcnB2_CA@mail.gmail.com>
Message-ID: <CADfFDC6EMTY4oxjLN9oH3JvCMSGY0Tp5sX1mqjJU1zDGrj_euA@mail.gmail.com>

On Wed, Aug 21, 2013 at 3:30 AM, ivo welch <ivo.welch at gmail.com> wrote:
> thx, deepayan:  how is stopifnot better than
>     if (!all(...)) stop()

But I am not claiming that it is!

If you think it is not useful, then don't use stopifnot(), use stop()
instead, and tell your students to do so as well.

> given that we have stopifnot() and I have seen it used often, I think
> my two suggestions would make it better.

Maybe it will (in some specific use cases). But looking at your
suggestion purely from the point of view of "is it worth incorporating
into base R?", I don't see enough justification. The disadvantage is
that it will complicate a simple function. The supposed advantage is
only an advantage when you use stopifnot() in a way that was not
intended, whereas there is already an alternative that does almost
exactly what you want (at least you haven't yet explained why you are
not happy with stop()). Interpolated strings may be cool, but I don't
see a big readability advantage of

if (!is.matrix(m)) stop("m is not a matrix, but a {{class(m)}}")

over

if (!is.matrix(m)) stop("m is not a matrix, but a ", class(m))

Note that I'm not saying that stop() is perfect or anything, or that
there is no need for alternatives. Just that I'm not convinced that
the base R changes you want are justified.

-Deepayan



[Rd] Extending suggestion for stopifnot
Deepayan Sarkar