Replicating a random sample produces repeat results

Issue #131 invalid
Nick Timkovich created an issue

Replicating a random function produces identical results. Is the seed held constant?

###Steps to Reproduce/Actual Results

$ python -c "import rpy2.robjects as ro;print ro.r.replicate(3,ro.r.rnorm(3))"
            [,1]        [,2]        [,3]
[1,] -0.08482239 -0.08482239 -0.08482239
[2,]  0.31146542  0.31146542  0.31146542
[3,]  0.53558629  0.53558629  0.53558629

###Expected Results Results should be varied:

$ R
R version 2.14.1 (2011-12-22)
[...]
> replicate(3,rnorm(3))
           [,1]       [,2]       [,3]
[1,] -0.8335674  1.4955445 -0.4020928
[2,]  0.7329928  1.8060759 -1.5338883
[3,] -0.4381838 -0.1636827 -0.2042676

###Reproducibility Deterministic

###Build & Platform Rpy2 2.3.6 R 2.14.1 Python 2.7.3 Ubuntu 12.04 (32-bit)

Comments (4)

  1. Nick Timkovich reporter

    Actually I guess this isn't directly comparable; Python's creating the object (which fixes the random values), then R "replicates" it, while in pure-R it's replicating the function call(?). Not sure what the actual translation is (or should be).

  2. Laurent Gautier

    In the code snippet you have, rpy2 is merely calling the underlying R functions.

    The difference in behavior comes from the evaluation strategies used by the two languages (and I think that this is the sense of your last comment).

    In R, the code replicate(3, rnorm(3)) means: - call to replicate() with its arguments unevaluated - the code in replicate evaluates 3 times rnorm(3)

    In Python, the code replicate(3, rnorm(3)) means: - rnorm(3) is evaluated - replicate() and the one random vector obtained above is copied 3 times.

  3. Log in to comment