2

I'm using the future.callr that creates a new thread(?) every time a future is requested so it is calculated separately and the main R script can keep moving on.

I'm getting the following warning when my futures come back:

    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".

In the actual code I'm running, it's just loading some data and I don't know why (or care EDIT: I do care, see comments below) that it's generating random numbers. How do I stop that warning from being shown (either fixing the rng generation or just ignoring it)?

I've got a lot of lines with futures so I am hoping to be able to just set the option at the beginning somehow and not have to add it to every line.

Here's an example and my attempt to ignore the warning.

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)
Roger-123
  • 2,232
  • 1
  • 13
  • 33
  • "I don't know why (or care) that it's generating random numbers" You should care. This has the potential for some serious bugs. – Roland Oct 01 '21 at 07:04
  • @Roland - I was being a little flippant about that. I did look at it. The futures are just loading CSV (readr) and Excel (readxl) files (lots of them) and basic data shaping, so I'm not sure where random numbers might be coming into play. It's a concern, but the testing I've done so far hasn't shown any issues. I would definitely prefer a 'fix' rather than just ignore it. – Roger-123 Oct 01 '21 at 14:37

1 Answers1

3

See help("%seed%", package = "future").

You could either use %seed% like below:

b %<-% runif(1) %seed% TRUE # seed is set by future pkg
print(b)

# or
b %<-% runif(1) %seed% 1234567 # your seed
print(b)

Or to disable checking

options(future.rng.onMisuse = "ignore")
b %<-% runif(1)
print(b)
Jon Manese
  • 361
  • 1
  • 5
  • Is there any way to setup the `%seed%` argument as an option when setting options or `plan(callr)` so I don't have to add that to every line? – Roger-123 Oct 04 '21 at 21:28
  • 1
    It is not possible as of version 1.22.1. But I think it's an easy change: in https://github.com/HenrikBengtsson/future/blob/1.22.1/R/Future-class.R line 94 replace `seed = FALSE` with something like `seed = getOption("future.seed", FALSE)` then you can set it one time with `options(future.seed = TRUE)`. – Jon Manese Oct 05 '21 at 02:53