Created attachment 2002[details]
Avoid loading stats et al. when loading parallel
When loading the parallel package, it uses `stats::runif()` and when loading stats we also get graphics, grDevices, and utils. This prevents setting up a minimal R session with only base and parallel loaded. The memory usage with 'base' and 'parallel' alone is ~45 MiB whereas with all of the above it is ~102 MiB.
EXAMPLE:
$ R_DEFAULT_PACKAGES=base,parallel Rscript --vanilla --quiet -e "loadedNamespaces()"
[1] "graphics" "parallel" "utils" "grDevices" "stats" "base"
As understood from the patch, one can avoid stats::runif() by:
$ R_DEFAULT_PACKAGES=base Rscript --vanilla --quiet -e "x <- sample.int(1L); Sys.setenv(R_PARALLEL_PORT=11321); x <- loadNamespace('parallel'); loadedNamespaces()"
[1] "parallel" "base"
PATCH:
Looking into the code the fix is trivial. One can use `sample.int()` instead of `stats::runif()`. I've attached a patch.
For more details, see https://github.com/HenrikBengtsson/Wishlist-for-R/issues/8
Thanks

Thanks Martin. Yes, I was thinking about that truncation too. Your runif1 is certainly better emulation of runif().
Just to make sure, but I think you've got it: sample.int(1) is just to generate .Random.seed.