[S] clarification of "unexpected strings of zeros"

John Castelloe (jcaste@stat.uiowa.edu)
Wed, 16 Sep 1998 10:23:12 -0500


Yesterday I described some strange behavior of "rpois". I have narrowed
down the problem: it seems that an attempt to access a NULL array "freezes"
the random number generator! Here is a script of an actual S-Plus session
demonstrating the problem. I would be grateful for any explanations.

"foo" <- function()
{
x <- rpois(10,4)
cat("x =", x, "\n")
y <- NULL
if (x[1]>0)
{ y <- cbind(y,1:2)
}
z <- y[1,]
return(z)
}

> foo()
x = 3 5 6 5 7 2 3 1 3 1
[1] 1
.
. (plenty of normal behavior)
.
> foo()
x = 5 7 0 5 7 8 2 4 3 2
[1] 1
> foo()
x = 0 5 10 2 3 6 3 5 0 5
Error in [: No dim attribute for array subset: # NULL
Dumped
> foo()
x = 0 5 10 2 3 6 3 5 0 5
Error in [: No dim attribute for array subset: # NULL
Dumped
.
.
.
> foo()
x = 0 5 10 2 3 6 3 5 0 5
Error in [: No dim attribute for array subset: # NULL
Dumped
> foo()
x = 0 5 10 2 3 6 3 5 0 5
Error in [: No dim attribute for array subset: # NULL
Dumped
> foo <- function(){return(rpois(10,4))}
> foo()
[1] 0 5 10 2 3 6 3 5 0 5
> foo()
[1] 10 1 2 3 10 4 3 4 10 7
.
. (back to normal behavior)
.
> foo()
[1] 2 4 6 5 1 4 3 3 2 1

I know this is a toy function, but the implications could be much more
serious for a complicated program. I was able to duplicate this behavior
on both S-Plus 4.0.3 on Win95 and S-Plus 3.4 on an HP-UX workstation.

Thanks,
John

---------------------------------------------------------------
| John Castelloe phone: (319)335-2009 |
| Computer RA fax: (319)335-3017 |
| Dept. of Statistics web: http://www.stat.uiowa.edu/~jcaste |
| University of Iowa office: 269 SH |
---------------------------------------------------------------
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news