s-news
[Top] [All Lists]

Re: Splus returns NULL

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: Splus returns NULL
From: "David Huffer" <David.Huffer@csosa.gov>
Date: Fri, 19 Oct 2007 11:15:13 -0400
Thread-index: AcgSYtjvl9u0AxfESceFAQTue/CdFA==
Thread-topic: [S] Splus returns NULL
On Friday, October 19, 2007, 10:00:56 AM Dennis Fisher wrote:

> When   a  conditional  statement  tests  as
> negative,  Splus  (version 7.0.0 running on
> RedHat Linux) returns NULL.
>
> for example:
>
>
> X       <- T
> if (!X) cat("hello")
>
> returns     NULL.     I     have     tested
> options(warn=-1)  and options(echo=F) to no
> avail.  In  R,  the  same  commands  return
> nothing.

The conditional evaluation of true.expr in:

   if ( test ) true.expr

means  that if test is TRUE then true.expr is
evaluated  and returned. If it is not true an
empty  value (NULL) is returned. In your case
since  test  is  not  true,  true.expr is not
evaluated   and  an  empty  value  (NULL)  is
returned instead.

>  Any ideas how to prevent the NULL returns?

Wrap it in a function like...

   noNull <- function ( X = NULL ) {
    if ( !X ) cat ( "hello\n" )
    invisible()
   }

   > noNull ( X=TRUE)
   > noNull ( X=FALSE)
   hello
   >

--
Thanks!
 David

<Prev in Thread] Current Thread [Next in Thread>