@@ -588,6 +588,41 @@ bgm = function(
588588 nThreads = cores , seed = seed , progress_type = progress_type
589589 )
590590
591+
592+ userInterrupt = any(vapply(out , FUN = `[[` , FUN.VALUE = logical (1L ), " userInterrupt" ))
593+ if (userInterrupt ) {
594+ warning(" Stopped sampling after user interrupt, results are likely uninterpretable." )
595+ # Try to prepare output, but catch any errors
596+ output <- tryCatch(
597+ prepare_output_bgm(
598+ out = out , x = x , num_categories = num_categories , iter = iter ,
599+ data_columnnames = if (is.null(colnames(x ))) paste0(" Variable " , seq_len(ncol(x ))) else colnames(x ),
600+ is_ordinal_variable = variable_bool ,
601+ warmup = warmup , pairwise_scale = pairwise_scale ,
602+ main_alpha = main_alpha , main_beta = main_beta ,
603+ na_action = na_action , na_impute = na_impute ,
604+ edge_selection = edge_selection , edge_prior = edge_prior , inclusion_probability = inclusion_probability ,
605+ beta_bernoulli_alpha = beta_bernoulli_alpha , beta_bernoulli_beta = beta_bernoulli_beta ,
606+ dirichlet_alpha = dirichlet_alpha , lambda = lambda ,
607+ variable_type = variable_type ,
608+ update_method = update_method ,
609+ target_accept = target_accept ,
610+ hmc_num_leapfrogs = hmc_num_leapfrogs ,
611+ nuts_max_depth = nuts_max_depth ,
612+ learn_mass_matrix = learn_mass_matrix ,
613+ num_chains = chains
614+ ),
615+ error = function (e ) {
616+ list (partial = out , error = conditionMessage(e ))
617+ },
618+ warning = function (w ) {
619+ # still salvage what we can
620+ list (partial = out , warning = conditionMessage(w ))
621+ }
622+ )
623+ return (output )
624+ }
625+
591626 # Main output handler in the wrapper function
592627 output = prepare_output_bgm (
593628 out = out , x = x , num_categories = num_categories , iter = iter ,
@@ -634,9 +669,5 @@ bgm = function(
634669 }
635670 }
636671
637- userInterrupt = any(vapply(out , FUN = `[[` , FUN.VALUE = logical (1L ), " userInterrupt" ))
638- if (userInterrupt )
639- warning(" Stopped sampling after user interrupt, results are likely uninterpretable." )
640-
641672 return (output )
642673}
0 commit comments