r - 如何使用 future.callr 抑制随机数生成警告?
问题描述
future.callr
每次请求未来时,我都会使用它创建一个新线程(?),因此它是单独计算的,主 R 脚本可以继续前进。
当我的期货回来时,我收到以下警告:
Warning message:
UNRELIABLE VALUE: Future (‘<none>’) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".
在我正在运行的实际代码中,它只是加载一些数据,我不知道为什么(或关心编辑:我确实关心,请参阅下面的评论)它正在生成随机数。如何阻止显示该警告(修复 rng 生成或忽略它)?
我有很多关于期货的行,所以我希望能够以某种方式在开头设置选项,而不必将其添加到每一行。
这是一个示例,我试图忽略该警告。
library(future.callr)
set.seed(1234567)
future.seed = TRUE
#normal random number - no problem
a<-runif(1)
print(a)
#random number in future, using callr plan
plan(callr, future.rng.onMisuse = 'ignore')
b %<-% runif(1)
print(b)
解决方案
见help("%seed%", package = "future")
。
您可以%seed%
像下面这样使用:
b %<-% runif(1) %seed% TRUE # seed is set by future pkg
print(b)
# or
b %<-% runif(1) %seed% 1234567 # your seed
print(b)
或禁用检查
options(future.rng.onMisuse = "ignore")
b %<-% runif(1)
print(b)
推荐阅读
- python - 如何在 Django 中的模型和相关模型中进行弹性搜索
- android - 为什么 childFragmentManager.popBackStack() 在 Fragment for Android 中不起作用?
- java - 如何从kotlin初始化java对象
- flutter - 如何将 google admob 与颤振项目集成?
- java - 如何使用 Junit5 为 HashMap 编写 Mockito 测试用例?
- html - 我想事先将我自己的文本附加到 html 中的谷歌搜索中
- javascript - JavaScript 中字符串的长度
- django - 如何在 django 的 oneToOneField 上过滤不区分大小写
- macos - 下拉列表中图标图像的 QComboBox 样式
- javascript - 将解析的百分比数据转换为新数组