Re: [Rd] Extending suggestion for stopifnot

2013-08-21 Thread Deepayan Sarkar
On Wed, Aug 21, 2013 at 3:30 AM, ivo welch ivo.we...@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.

Re: [Rd] Extending suggestion for stopifnot

2013-08-21 Thread Geoff Jentry
first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) stop() allows for arbitrary strings __ R-devel@r-project.org mailing list

[Rd] Extending suggestion for stopifnot

2013-08-20 Thread ivo welch
I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Deepayan Sarkar
On Wed, Aug 21, 2013 at 12:11 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread R. Michael Weylandt michael.weyla...@gmail.com
On Aug 20, 2013, at 14:41, ivo welch ivo.we...@anderson.ucla.edu wrote: A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. I think one the HTML templating libraries (whisker or mustache or some such) provides something not unlike

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Peter Langfelder
On Tue, Aug 20, 2013 at 11:41 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Brian Rowe
If all you care about is emulating static type checking, then you can also accomplish the same thing with lambda.r using type constraints on function definitions. e.g. f(m) %::% matrix : matrix f(m) %as% { m } f(as.data.frame(matrix(rnorm(12),nrow=3))) Error in UseFunction(f, ...) : No

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread ivo welch
thx, deepayan: how is stopifnot better than if (!all(...)) stop() given that we have stopifnot() and I have seen it used often, I think my two suggestions would make it better. thx, michael: the %and% and %or% constructs are indeed relics of my perl background. my own definition is

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Gabor Grothendieck
On Tue, Aug 20, 2013 at 6:00 PM, ivo welch ivo.we...@gmail.com wrote: character string at the end of an existing function, stopifnot(). (2) I think estrings (that behave like characters but are interpolated before printout) are useful in the same way perl interpolated strings are useful. The

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread ivo welch
functionality is nice. syntax is weird. I think I would have preferred an interpolate function call. stop( i(class is `class(pi)` and $pi) ) three typing letters, too, and more logical. most importantly, I wish we had some form of this in base R from the outset--whatever it is--so that my

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Hadley Wickham
first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) Another option is to just generate better error messages automatically, e.g.: library(assertthat) x - 1:10 assert_that(is.matrix(x)) Error: x

Re: [Rd] Extending suggestion for stopifnot

2013-08-20 Thread Martin Morgan
On 08/20/2013 11:41 AM, ivo welch wrote: A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) a variant with more traditional syntax might be if (!is.matrix(m))