[S] Summary: unexpected strings of zeros

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


Thanks to Stephen Kaluzny and Bill Dunlap of Mathsoft, Inc. for the quick
and elegant explanation of the behavior-- it is NOT a bug, and I now
realize how it can be a useful device for error tracking (and something I
could have probably discovered from the help pages-- oops). (It just
happened to be problematic for me in the application I was using). See
details below:

Stephen Kaluzny writes:

All the random number generators in S-PLUS use a seed that is stored in
the object .Random.seed in the current working database (.Data or _Data).
A new version of .Random.seed gets created after each call to one of the
random number generators and .Random.seed gets written out to .Data at
the end of the top level expression. If you set this seed to the same
value you will reproduce your random numbers, e.g.

save.seed <- .Random.seed
x <- rpois(5, 10)
.Random.seed <- save.seed
y <- rpois(5, 10)

will result in y == x.

If you have an error in your function the database protection mechanism
does not write out any objects to .Data, this includes .Random.seed.
This is vary useful if you want to track down an error where some of the
data was generated by random numbers. You were continuely generating
the same random numbers in your function and thus getting the same error.

You could just call runif(1) before executing your function after the
error to set a new seed but the better solution is to fix your function
so if that type of data is generated again you do not get the error.

Bill Dunlap writes:

Any *error* stops changes to datasets changed in that top level
expression from being permanently saved. The seed for the random
number generator (.Random.seed) is an ordinary dataset and does not get
saved after an error. Hence rerunning the function will get the same
value of .Random.seed.

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