[R] Bug report: override stopifnot() ?
bgunter.4567 at gmail.com
Mon Mar 12 19:43:44 CET 2018
Please stop this line of queries/"suggestions/speculations and read the
relevant docs **carefully**.
For example, from ?"=="
Do not use == and != for tests, such as in if expressions, where you must
get a single TRUE or FALSE. Unless you are absolutely sure that nothing
unusual can happen, you should use the identical
<http://127.0.0.1:22171/help/library/base/help/identical> function instead.
So you have already violated that specific warning, which led to the
confusion you evidence. Specifically:
> Matrix(1)== Matrix(1)
1 x 1 Matrix of class "lsyMatrix"
That is, the result is not a logical but a (S4) object of class "lsyMatrix"
that contains a logical. Whence your (expected) error message.
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Mar 12, 2018 at 10:53 AM, Stepan Kasal <kasal at ucw.cz> wrote:
> On Mon, Mar 12, 2018 at 09:30:59AM -0700, William Dunlap wrote:
> > Why don't you use
> > stopifnot( all(m1 == m2) )
> > ?
> good question. Even though I use
> aseert np.all(m1 == m2)
> when working with NumPy, I got accustomed to the "handy shortcut"
> that I can omit all() with R vectors and matrices.
> Then I got trapped with the thing I reported.
> On a second thought, omitting all() might have been bad idea from
> the beginning; I should rather write all() routinely.
> (It also reminds me that all.equal() is the right one in most cases.)
> Is it true that using stopifnot() with non-scalar is considerd bad style?
> If yes, could be perhaps stopifnot() enhanced to issue a warning to
> teach new users of R, at least when they start using library(Matrix)?
> If not, then enhancing stopifnot() to handle the case may be a good idea.
> I also noticed the following:
> > a <- Matrix(1)
> > stopifnot(a == a)
> Error: a == a is not TRUE
> > if(a==a)print(1)
> Error in if (a == a) print(1) : argument is not interpretable as logical
> Neither does work, but the first error message is much more confusing.
> When thinking about it, stopifnot() should really issue a better error
> message in this case. Patch attached. But I should perhaps send
> it also to R-devel.
> Stepan Kasal
> > On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal <kasal at ucw.cz> wrote:
> > > Hello,
> > > I stumbled over a problem:
> > > stopifnot(m1 == m2)
> > >
> > > It works with vector or matrix, but does not work for classes from
> > > package.
> > >
> > > In the source of stopifnot(), there is all(m1 == m2) that would just
> > > but there is also is.logical(m1 == m2) that id FALSE.
> > >
> > > Would it be possible if Matrix package redefined stopifnot() ?
> > >
> > > (If there is a bug tracking database for package Matrix, I would be
> > > to insert this report there.)
> > >
> > > Thank you very much for the package,
> > > Stepan Kasal
> > >
> > > ______________________________________________
> > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/
> > > posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help