From 153330375b551f368bbe1a332e03f67538abd33e Mon Sep 17 00:00:00 2001 From: Dan Snow <31494343+dfsnow@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:41:22 -0800 Subject: [PATCH] Set global R seed inside setup (#77) --- R/setup.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/setup.R b/R/setup.R index 2d8bf3f..f955b06 100644 --- a/R/setup.R +++ b/R/setup.R @@ -57,6 +57,13 @@ if (knitr::is_html_output() || knitr::is_latex_output()) { } assign(params_obj_name, read_yaml(here("params.yaml"))) +# Set the random seed for reproducibility. This is currently used in two places: +# 1. Within Tidymodels workflows whenever sampling is used e.g. for KNN impute +# 2. Within the CV loop to make random folds that are consistent across runs +# Note that LightGBM uses its own set of seeds i.e. this seed doesn't affect +# whether the model itself is deterministic +set.seed(get(params_obj_name)$model$seed) + # Get the number of available physical cores to use for multi-threading # Lightgbm docs recommend using only real cores, not logical # https://lightgbm.readthedocs.io/en/latest/Parameters.html#num_threads