@@ -250,16 +250,16 @@ bart <- function(
250250 drop_vars_variance <- variance_forest_params_updated $ drop_vars
251251 num_features_subsample_variance <- variance_forest_params_updated $ num_features_subsample
252252
253- # Set a function-scoped RNG if user provided a random seed
254- custom_rng <- random_seed > = 0
255- if (custom_rng ) {
256- # Store original global environment RNG state
257- original_global_seed <- .Random.seed
258- # Set new seed and store associated RNG state
259- set.seed(random_seed )
260- function_scoped_seed <- .Random.seed
261- }
262-
253+ # Set a function-scoped RNG if user provided a random seed
254+ custom_rng <- random_seed > = 0
255+ if (custom_rng ) {
256+ # Store original global environment RNG state
257+ original_global_seed <- .Random.seed
258+ # Set new seed and store associated RNG state
259+ set.seed(random_seed )
260+ function_scoped_seed <- .Random.seed
261+ }
262+
263263 # Check if there are enough GFR samples to seed num_chains samplers
264264 if (num_gfr > 0 ) {
265265 if (num_chains > num_gfr ) {
@@ -1748,27 +1748,27 @@ bart <- function(
17481748 }
17491749 class(result ) <- " bartmodel"
17501750
1751- # Clean up classes with external pointers to C++ data structures
1752- if (include_mean_forest ) {
1753- rm(forest_model_mean )
1754- }
1755- if (include_variance_forest ) {
1756- rm(forest_model_variance )
1757- }
1758- rm(forest_dataset_train )
1759- if (has_test ) {
1760- rm(forest_dataset_test )
1761- }
1762- if (has_rfx ) {
1763- rm(rfx_dataset_train , rfx_tracker_train , rfx_model )
1764- }
1765- rm(outcome_train )
1766- rm(rng )
1767-
1768- # Restore global RNG state if user provided a random seed
1769- if (custom_rng ) {
1770- .Random.seed <- original_global_seed
1771- }
1751+ # Clean up classes with external pointers to C++ data structures
1752+ if (include_mean_forest ) {
1753+ rm(forest_model_mean )
1754+ }
1755+ if (include_variance_forest ) {
1756+ rm(forest_model_variance )
1757+ }
1758+ rm(forest_dataset_train )
1759+ if (has_test ) {
1760+ rm(forest_dataset_test )
1761+ }
1762+ if (has_rfx ) {
1763+ rm(rfx_dataset_train , rfx_tracker_train , rfx_model )
1764+ }
1765+ rm(outcome_train )
1766+ rm(rng )
1767+
1768+ # Restore global RNG state if user provided a random seed
1769+ if (custom_rng ) {
1770+ .Random.seed <- original_global_seed
1771+ }
17721772
17731773 return (result )
17741774}
0 commit comments