Re: [R] srt --- slope text with function?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun 12 Feb 2006 - 10:17:40 EST

On 2/11/06, Patricia J. Hawkins <phawkins@connact.com> wrote:
> >>>>> "iw" == ivo welch <ivowel@gmail.com> writes:
>
> iw> * SUGGESTION: can we please offer the "?:" operator ala C in
> iw> addition to ifelse()? This would make R code prettier.
>
> R:
> if (condition) xxx else yyy
> if (condition) xxx else if (yyy) zzz else qqq
>
> C:
> condition ? xxx : yyy;
> condition ? xxx : yyy ? zzz : qqq;
>
> If this is a beauty contest, or a readability contest, I'll take R!
>
> ?: is pleasant in C because it avoids so much of the C syntactic
> sugar, of which R is largely free.
>
> As for ifelse(), for a trivial example, try running:
> ifelse(array(rep(c(1,0), 50), dim=c(10,10)), "00", "99")

Maybe this is not the point but in this particular example we could write:

matrix(c("00", "99"), 10, 10)

>
> iw> Similarly, perl has a nice construct, which would be lovely, but
> iw> which may not jive with the
> iw> R syntax:
> iw> condition or die("the condition", condition, "has failed");
> iw> condition and cat("my condition", condition, "is met");
>
> if (!condition) stop("the condition", condition, "has failed")
> if (condition) cat("my condition", condition, "is met")
>

Try this:

stopifnot(condition)

> --
> Patricia J. Hawkins
> Hawkins Internet Applications
> www.hawkinsia.com
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Feb 12 10:20:02 2006

This archive was generated by hypermail 2.1.8 : Tue 14 Feb 2006 - 00:40:33 EST