Runs a specified R script in a background vanilla R session to verify reproducibility. If the script fails due to missing dependencies or variables, it interactively prompts the user to inject the necessary fixes directly into the file.
Value
Invisibly returns a named list with components: status ("done" or
"cancelled"), script, success (logical), and attempts (integer).
Details
The function implements a "stress-test" for script reproducibility:
Prompts the user to select an R script from the current directory.
Executes the script using `system2("Rscript", args = c("–vanilla", ...))`, ensuring no workspace variables or attached packages from the current session interfere.
If the script crashes, it captures the `stderr` output and presents a crash report to the user.
Interactively offers to fix the crash by:
Injecting a missing `library()` call at the top of the file.
Injecting a custom code snippet (e.g., a missing variable definition).
Automatically updates the file and re-runs the simulation until the script executes successfully or the user aborts.
Warning
This function modifies files on disk or the global environment. Please ensure you have a backup or are using version control (e.g., Git) before execution.
Examples
if (interactive()) {
simulate_clean_room()
}
