Inspired by a Stack Overflow question, here’s a way of tracking what’s been modifying the .Random.seed.
Since R makes static analysis impossible in general, the following is a runtime tracer that injects itself into the .Random.seed variable via an active binding:
NOTE: This will only work properly if called directly by the user at the top level. In particular, it won’t work inside an RMarkdown report or similar, where the top-level call is
rmarkdown::render(), orknitr::knit(), or similar; rather than, say,sample().
trace_random_seed()