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

Patricia J. Hawkins phawkins at connact.com
Sat Feb 11 21:30:41 CET 2006


>>>>> "iw" == ivo welch <ivowel at 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")

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")

-- 
Patricia J. Hawkins
Hawkins Internet Applications
www.hawkinsia.com




More information about the R-help mailing list