R Reproducibility
Record the runtime and control randomness in a deliberate process.
How it works
A reproducible experiment records its source, data, package versions, random-generator settings and evaluation choices. set.seed controls random draws in the current R process; it does not document those other decisions. Use fresh Rscript --vanilla processes for these examples rather than relying on a saved workspace with unknown objects.
Run this R example
These examples run locally with R, not PHP, Python or JavaScript. The reviewed baseline is R 4.5.2 on Windows x64/UCRT, using only packages shipped with R. This is a tested version, not a newest-release claim. Install your own R from the official R project; an IDE is optional. Save the complete source as reproducibility.R in a separate learning folder and run Rscript --vanilla reproducibility.R. Keep code and fictional fixtures separate from a real project.
Bhylu has no R browser runner. There is no Try in playground link because the existing Python and JavaScript editors do not execute R. No package installation, account, network dataset, Apache, MySQL or PHP setting is needed to run these base-R sources.
The complete download uses a local scope, restores its temporary options and treats unexpected warnings as errors. Examples that handle an expected warning do so narrowly. Random examples change only their R process’s RNG state. File examples own their temporary output; figure examples leave their named PNG in the current learning folder and refuse to overwrite it. Use a new empty folder to rerun a figure.
Download the complete reproducibility.R · Download all source files with hash checks
For the optional collection downloader, save download-examples.mjs in an empty folder and run node download-examples.mjs. Local preview before publishing uses node download-examples.mjs http://127.0.0.1:8000/examples/r/. It refuses an existing bhylu-r-examples folder and does not install or execute R.
Example
local({
previous_options <- options(warn = 2, digits = 8, stringsAsFactors = FALSE)
on.exit(options(previous_options), add = TRUE)
set.seed(42)
first <- runif(5)
set.seed(42)
second <- runif(5)
cat("same seed repeats here:", identical(first, second), "\n")
cat("R baseline:", as.character(getRversion()), "\n")
cat("stats namespace available:", requireNamespace("stats", quietly = TRUE), "\n")
invisible(NULL)
})
Focus on the lesson operations
This excerpt omits the complete script’s option/resource setup. Use the full download to execute it.
set.seed(42)
first <- runif(5)
set.seed(42)
second <- runif(5)
cat("same seed repeats here:", identical(first, second), "\n")
cat("R baseline:", as.character(getRversion()), "\n")
cat("stats namespace available:", requireNamespace("stats", quietly = TRUE), "\n")
Expected result
same seed repeats here: TRUE R baseline: 4.5.2 stats namespace available: TRUE
The reported version is read from the actual interpreter and may differ on a learner’s installation. The demonstrated repeatability is within this reviewed runtime. Capture sessionInfo for a real project, but do not expose private machine paths in public diagnostic pages.
For API behaviour, consult the official Introduction to R and your installed help pages. These small examples do not establish real-world statistical conclusions or production performance.