Set seed prior to rendering #8409
Replies: 2 comments 8 replies
-
Hum, seems very tricky as even setting the seed for This would be indeed a nice enhancement. |
Beta Was this translation helpful? Give feedback.
-
The question is not "how do I use Re: @cderv: "This goes beyond reproducibility as a document would not be self-contained in their execution." - I think with RNGs the documents are never "self-contained" in a sense, in that the RNG state is not determined by the document itself (unless explicitly set in the document), right? So the ask is a way of determining the initial RNG state(s) besides "whatever the engines initializes them to". |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I opened this request over on quarto-r, but was directed here from https://github.com/quarto-dev/quarto-r/issues/90.
When generating many documents from a single source file, it is extremely useful to be able to set the random seed prior to rendering. That way, you can take a single document and render it many times with different, but reproducible, results. For instance, I use this to generate random assignments in a teaching context.
With Rmarkdown, I can set a random seed prior to rendering, and I'll get the same document every time. Consider the following
Rmd
file (which I'm callingtest_seed_rmd.Rmd
):If I use
withr::with_seed
to compile it:then I get the output
## [1] -0.5604756
every time.Because of the way Quarto works (using the CLI), this seems to be more difficult (also, because it is designed with support for multiple languages in mind, and each has their own seed - I imagine that makes thinking about RNGs hard). I cannot, for instance, do this:
and expect a reproducible document, because the rendering is passed off to a CLI program.
@cderv brainstormed some ideas here (https://github.com/quarto-dev/quarto-r/issues/90#issuecomment-1905839682) and I was also thinking environment variables might work (e.g. setting an environment variable as a seed that is then picked up within the document)? (That's not ideal, though, because it requires extra code in the document itself).
Is there any way of making this work?
Beta Was this translation helpful? Give feedback.
All reactions