From 72ba4fbff436c45a49de515b4f0922729070acdb Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Thu, 4 Dec 2025 09:16:15 -0800 Subject: [PATCH 1/2] safe computation of condition number --- R/get_condition_number_for_fit.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/get_condition_number_for_fit.R b/R/get_condition_number_for_fit.R index 6ae1f98..c1ae378 100644 --- a/R/get_condition_number_for_fit.R +++ b/R/get_condition_number_for_fit.R @@ -15,7 +15,13 @@ get_condition_number_for_fit <- function( if(!inherits(mat, "matrix") || diff(dim(mat)) != 0) { cli::cli_abort("Needs a square matrix to calculate condition number.") } - calc_condition_number(mat) + tryCatch({ + cond <- calc_condition_number(mat) + }, error = function(e) { + cli::cli_alert_warning("Failed to calculate condition number: {e}") + cond <- NA + }) + cond } #' Calculate the condition number given a matrix From 61b5e560265e3ac7390cbeae1a4e06f20dc6293d Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Thu, 4 Dec 2025 09:16:50 -0800 Subject: [PATCH 2/2] safe computation of condition number --- R/get_condition_number_for_fit.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/get_condition_number_for_fit.R b/R/get_condition_number_for_fit.R index c1ae378..9de4ff5 100644 --- a/R/get_condition_number_for_fit.R +++ b/R/get_condition_number_for_fit.R @@ -13,7 +13,8 @@ get_condition_number_for_fit <- function( } mat <- as.matrix(fit$correlation_matrix) if(!inherits(mat, "matrix") || diff(dim(mat)) != 0) { - cli::cli_abort("Needs a square matrix to calculate condition number.") + cli::cli_alert_warning("Needs a square matrix to calculate condition number.") + return(NA) } tryCatch({ cond <- calc_condition_number(mat)