Skip to content

Making an if condition variable ?

2 messages · ce, Bert Gunter

ce
#
well, not that simple. My original condition and changes are more complicated than I post in r-help for simplicity purposes . Original condition is something like :

 if (   a > 0  & ( b[1] > b[2] ) |  c == TRUE ) 

and I might change it to

if ( a == 0 &  ( b[1] < b[2] ) & d > 10 ) 

then I need to have a bunch of functions and I will forget which function I used. 

-----Original Message-----
From: "Rainer M Krug" [Rainer at krugs.de]
Date: 06/02/2016 09:08 AM
To: "ce" <zadig_1 at excite.com>
CC: "Jeff Newmiller" <jdnewmil at dcn.davis.ca.us>, r-help at r-project.org
Subject: Re: Making an if condition variable ?

"ce" <zadig_1 at excite.com> writes:
In this case - why not use a function instead of the condition?

cond <- function(x){x>0}
and than

if (cond(4)) {...}

might be the easiest in this case?

or, more flexible,

cond <- function(...){x>0}

if (cond(x=3)) {...}

Cheers,

Rainer

  
    
#
You need to rethink. You'll do better in the long -- and probably
short, too -- run working within the language's paradigms rather than
resisting them.

(It's not that R's paradigms are in any sense "the best"; other
languages have different paradigms and you would do better in those
languages with their paradigms rather than with R's).

For example, you could have a single function that returns the
conditional function of your choice by calling the overall function
with an appropriate keyword.  Etc.

Cheers,
Bert


Bert Gunter

"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 Thu, Jun 2, 2016 at 7:50 AM, ce <zadig_1 at excite.com> wrote: