From Arne Kovac <maak@stats.bris.ac.uk>  Fri Jul 25 04:51:25 1997
From: Arne Kovac <maak@stats.bris.ac.uk> (Arne Kovac)
Date: Fri, 25 Jul 1997 03:51:25 +0000 (GMT)
Subject: R-alpha: Treatment of seed
Message-ID: <Pine.LNX.3.95.970725033537.4471B-100000@ts1.bris.ac.uk>

There is a difference between R and S (or S-Plus, I'm not sure about
that) concerning the generation of random numbers.

If an error occurs during the execution of a function, the seed is
restored to its old value in S-Plus, but not in R. This feature of S-Plus
has just turned out to be very useful for me because I got an error
message during a small simulation for a certain choice of parameters.

Here is a silly example:

R> silly<-function()
+ {
+ tmp<-rnorm(5)
+ unknownfunction()
+ }
R> .Random.seed
[1]  8886  1153 10190
R> silly()
Error: couldn't find function "unknownfunction"
R> .Random.seed
[1]  9859  1963 19516


Splus> silly<-function()
+ {
+ tmp<-rnorm(5)
+ unknownfunction()
+ }
Splus> .Random.seed
 [1] 37 31 60  6 22  0 47 15  0 30 41  0
Splus> silly()
Error in silly(): couldn't find function "unknownfunction"
Dumped
Splus> .Random.seed
 [1] 37 31 60  6 22  0 47 15  0 30 41  0

Arne Kovac

-- 
Arne Kovac
School of Mathematics           Phone: +44 (0117) 942 7551
University of Bristol           A.Kovac@bristol.ac.uk    
University Walk                 http://www.stats.bris.ac.uk/~maak
Bristol, BS8 1TW, U.K.



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: Treatment of seed
Arne Kovac