为什么 RStudio 在查看期间调用随机生成器?

Why does RStudio calls a random generator during View?

我在 Mac 上使用 RStudio 0.99.467 和 R 3.2.2,我注意到 View 调用了随机数生成器或类似的东西。以下是代码:

set.seed(1) # not needed when I run it on RStudio, but needed on R
rs <- .Random.seed
cat(76 + 8)
all(.Random.seed == rs)
# TRUE  -- because a simple function shouldn't change the random numbers
View(3)
all(.Random.seed == rs)
# FALSE -- ???

实际上,唯一的区别是.Random.seed

的第二个数字
all((.Random.seed == rs)[-2])
# TRUE

似乎总是增加 10 个单位

.Random.seed[2] - rs[2]
# 10

这是 View 函数的预期行为还是我 运行 版本中的错误?

这确实是预料之中的。 RStudio 0.99 中的数据查看器使用 R sample 函数为您的数据生成随机缓存键。 0.98 中的数据查看器没有这样做(它只是生成原始 HTML)。

我刚刚记录了一个问题,以便我们考虑在未来的版本中消除这种副作用(我同意查看数据会更改您的随机种子是出乎意料的)。