Henrik Bengtsson
2021-Sep-17 08:47 UTC
[Rd] WISH: set.seed(seed) to produce error if length(seed) != 1 (now silent)
Hi, according to help("set.seed"), argument 'seed' to set.seed() should be: a single value, interpreted as an integer, or NULL (see ?Details?).>From code inspection (src/main/RNG.c) and testing, it turns out thatif you pass a 'seed' with length greater than one, it silently uses seed[1], e.g.> set.seed(1); sum(.Random.seed)[1] 4070365163> set.seed(1:3); sum(.Random.seed)[1] 4070365163> set.seed(1:100); sum(.Random.seed)[1] 4070365163 I'd like to suggest that set.seed() produces an error if length(seed)> 1. As a reference, for length(seed) == 0, we get:> set.seed(integer(0))Error in set.seed(integer(0)) : supplied seed is not a valid integer /Henrik
Avraham Adler
2021-Sep-17 10:06 UTC
[Rd] WISH: set.seed(seed) to produce error if length(seed) != 1 (now silent)
Hi, Henrik. I?m curious, other than proper programming practice, why? Avi On Fri, Sep 17, 2021 at 11:48 AM Henrik Bengtsson < henrik.bengtsson at gmail.com> wrote:> Hi, > > according to help("set.seed"), argument 'seed' to set.seed() should be: > > a single value, interpreted as an integer, or NULL (see ?Details?). > > From code inspection (src/main/RNG.c) and testing, it turns out that > if you pass a 'seed' with length greater than one, it silently uses > seed[1], e.g. > > > set.seed(1); sum(.Random.seed) > [1] 4070365163 > > set.seed(1:3); sum(.Random.seed) > [1] 4070365163 > > set.seed(1:100); sum(.Random.seed) > [1] 4070365163 > > I'd like to suggest that set.seed() produces an error if length(seed) > > 1. As a reference, for length(seed) == 0, we get: > > > set.seed(integer(0)) > Error in set.seed(integer(0)) : supplied seed is not a valid integer > > /Henrik > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Sent from Gmail Mobile [[alternative HTML version deleted]]