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
|