@@ -259,12 +259,16 @@ construct_forecast_models <- function(full_data_tbl,
259259 cli :: cli_h2(" Running Combo: {combo_value}" )
260260
261261 # Copy functions into global environment within azure batch
262- if (parallel_processing == " azure_batch" ) {
263- global_env <- .GlobalEnv
264- export_env <- global_env $ azbatchenv $ exportenv
265-
266- for (n in ls(export_env , all.names = TRUE )) {
267- assign(n , get(n , export_env ), global_env )
262+ if (! is.null(parallel_processing )) {
263+ if (parallel_processing == " azure_batch" ) {
264+
265+ global_env <- .GlobalEnv
266+ export_env <- global_env $ azbatchenv $ exportenv
267+
268+ for (n in ls(export_env , all.names = TRUE )) {
269+ assign(n , get(n , export_env ), global_env )
270+ }
271+
268272 }
269273 }
270274
@@ -274,13 +278,22 @@ construct_forecast_models <- function(full_data_tbl,
274278 run_data_full_tbl <- full_data_tbl %> %
275279 combo_specific_filter(combo_value ,
276280 combo_variables )
277-
281+
278282 cli :: cli_h3(" Initial Feature Engineering" )
279283
284+ # Run all recipes
285+ if (is.null(recipes_to_run )) {
286+ run_all_recipes_override <- FALSE
287+ } else if (recipes_to_run == " all" ) {
288+ run_all_recipes_override <- TRUE
289+ } else {
290+ run_all_recipes_override <- FALSE
291+ }
292+
280293 # recipe 1: standard feature engineering
281294 run_data_full_recipe_1 <- NULL
282295
283- if (is.null(recipes_to_run ) | " R1" %in% recipes_to_run | sum( recipes_to_run == " all " ) == 1 ) {
296+ if (is.null(recipes_to_run ) | " R1" %in% recipes_to_run | run_all_recipes_override ) {
284297
285298 run_data_full_recipe_1 <- run_data_full_tbl %> %
286299 multivariate_prep_recipe_1(external_regressors = external_regressors ,
@@ -301,7 +314,7 @@ construct_forecast_models <- function(full_data_tbl,
301314 # recipe 2: custom horizon specific feature engineering
302315 run_data_full_recipe_2 <- NULL
303316
304- if ((is.null(recipes_to_run ) & date_type %in% c(" month" , " quarter" , " year" )) | " R2" %in% recipes_to_run | sum( recipes_to_run == " all " ) == 1 ) {
317+ if ((is.null(recipes_to_run ) & date_type %in% c(" month" , " quarter" , " year" )) | " R2" %in% recipes_to_run | run_all_recipes_override ) {
305318
306319 run_data_full_recipe_2 <- run_data_full_tbl %> %
307320 multivariate_prep_recipe_2(external_regressors = external_regressors ,
@@ -332,7 +345,7 @@ construct_forecast_models <- function(full_data_tbl,
332345 combined_models_recipe_2 <- modeltime :: modeltime_table()
333346
334347 # parallel processing
335- if (run_model_parallel == TRUE & parallel_processing != " local_machine " ) {
348+ if (run_model_parallel == TRUE ) {
336349 parallel_args <- init_parallel_within(parallel_processing , num_cores )
337350 }
338351
@@ -353,12 +366,17 @@ construct_forecast_models <- function(full_data_tbl,
353366 models_to_go_over <- names(model_list )
354367
355368 # PCA
356- if (sum(pca == TRUE ) == 1 | (combo_value == " All-Data" & is.null(pca )) | (is.null(pca ) & date_type %in% c(" day" , " week" ))) {
369+ if ((combo_value == " All-Data" & is.null(pca )) | (is.null(pca ) & date_type %in% c(" day" , " week" ))) {
370+ run_pca <- TRUE
371+ } else if (is.null(pca )) {
372+ run_pca <- FALSE
373+ } else if (pca == TRUE ) {
357374 run_pca <- TRUE
358375 } else {
359376 run_pca <- FALSE
360377 }
361-
378+
379+ # train each model
362380 for (model_name in models_to_go_over ){
363381
364382 model_fn <- as.character(model_list [model_name ])
@@ -390,15 +408,15 @@ construct_forecast_models <- function(full_data_tbl,
390408 try(combined_models_recipe_1 <- modeltime :: add_modeltime_model(combined_models_recipe_1 ,
391409 mdl_called ,
392410 location = " top" ) %> %
393- update_model_description(1 , model_name ),
411+ modeltime :: update_model_description(1 , model_name ),
394412 silent = TRUE )
395413
396414 }else {
397415
398416
399417 freq_val <- frequency
400418
401- if (((model_name %in% r1_models ) | (model_name %in% r2_models )) & (is.null(recipes_to_run ) | sum( recipes_to_run == " all " ) == 1 | " R1" %in% recipes_to_run )){
419+ if (((model_name %in% r1_models ) | (model_name %in% r2_models )) & (is.null(recipes_to_run ) | run_all_recipes_override | " R1" %in% recipes_to_run )){
402420
403421 add_name <- paste0(model_name ," -R1" ,model_name_suffix )
404422 if (model_name %in% deep_nn_models ){
@@ -422,12 +440,12 @@ construct_forecast_models <- function(full_data_tbl,
422440 try(combined_models_recipe_1 <- modeltime :: add_modeltime_model(combined_models_recipe_1 ,
423441 mdl_called ,
424442 location = " top" ) %> %
425- update_model_description(1 , add_name ),
443+ modeltime :: update_model_description(1 , add_name ),
426444 silent = TRUE )
427445
428446 }
429447
430- if (model_name %in% r2_models & (" R2" %in% recipes_to_run | sum( recipes_to_run == " all " ) == 1 | (is.null(recipes_to_run ) & date_type %in% c(" month" , " quarter" , " year" )))){
448+ if (model_name %in% r2_models & (" R2" %in% recipes_to_run | run_all_recipes_override | (is.null(recipes_to_run ) & date_type %in% c(" month" , " quarter" , " year" )))){
431449
432450 add_name <- paste0(model_name ," -R2" ,model_name_suffix )
433451 try(mdl_called <- invoke_forecast_function(fn_to_invoke = model_fn ,
@@ -446,7 +464,7 @@ construct_forecast_models <- function(full_data_tbl,
446464 try(combined_models_recipe_2 <- modeltime :: add_modeltime_model(combined_models_recipe_2 ,
447465 mdl_called ,
448466 location = " top" ) %> %
449- update_model_description(1 , add_name ),
467+ modeltime :: update_model_description(1 , add_name ),
450468 silent = TRUE )
451469 }
452470
@@ -651,7 +669,7 @@ construct_forecast_models <- function(full_data_tbl,
651669 try(combined_ensemble_models <- modeltime :: add_modeltime_model(combined_ensemble_models ,
652670 mdl_ensemble ,
653671 location = " top" ) %> %
654- update_model_description(1 , add_name ),
672+ modeltime :: update_model_description(1 , add_name ),
655673 silent = TRUE )
656674 }
657675
@@ -746,7 +764,7 @@ construct_forecast_models <- function(full_data_tbl,
746764 }
747765
748766 # stop parallel processing
749- if (run_model_parallel == TRUE & parallel_processing != " local_machine " ){
767+ if (run_model_parallel == TRUE ){
750768 exit_parallel_within(parallel_args )
751769 }
752770
0 commit comments