Skip to content
Prev 46397 / 63421 Next

Extending suggestion for stopifnot

On Tue, Aug 20, 2013 at 11:41 AM, ivo welch <ivo.welch at anderson.ucla.edu> wrote:
I think using a function (in this case paste) is cleaner:

paste("m is not a matrix, but a", class(m))

It avoids adding a new convention ("evaluate everything between {{
}}") and has additional arguments.
In R you can write it as

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

Examples:

m = 1
Error: m is not a matrix but a numeric
[1] TRUE

But the construct

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

is more readable for people not used to Pearl.