Skip to content

Commit

Permalink
Improved error handling functions in CoxPH
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcorneliusmartin committed May 3, 2024
1 parent 7c11f09 commit 16cd060
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
17 changes: 9 additions & 8 deletions vtg.coxph/src/R/RPC_compute_summed_z.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
#' numeric vector with sums and named index with covariates.
RPC_compute_summed_z <- function(df, subset_rules, expl_vars, time_col,
censor_col, types = NULL, extend_data = TRUE) {

# Data pre-processing specific to EURACAN
if (extend_data){
df <- vtg.preprocessing::extend_data(df)
}
# Data pre-processing and filtering specific to EURACAN
df <- tryCatch(
vtg.preprocessing::subset_data(df, subset_rules),
{
if (extend_data) {
df <- vtg.preprocessing::extend_data(df)
}
df <- vtg.preprocessing::subset_data(df, subset_rules)
df
},
error = function(e) {
return(vtg::error_format(conditionMessage(e)))
vtg::error_format(conditionMessage(e))
}
)

if (!is.null(df$error)) {
vtg::log$error(df$error)
return(df)
Expand Down
18 changes: 10 additions & 8 deletions vtg.coxph/src/R/RPC_get_unique_event_times_and_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
RPC_get_unique_event_times_and_counts <- function(df, expl_vars, subset_rules, time_col,
censor_col, types = NULL,
extend_data = TRUE) {
# Data pre-processing specific to EURACAN
if (extend_data){
df <- vtg.preprocessing::extend_data(df)
}
# Data pre-processing and filtering specific to EURACAN
df <- tryCatch(
vtg.preprocessing::subset_data(df, subset_rules),
{
if (extend_data) {
df <- vtg.preprocessing::extend_data(df)
}
df <- vtg.preprocessing::subset_data(df, subset_rules)
df
},
error = function(e) {
return(vtg::error_format(conditionMessage(e)))
vtg::error_format(conditionMessage(e))
}
)

if (!is.null(df$error)) {
vtg::log$error(df$error)
return(df)
Expand All @@ -36,7 +38,7 @@ RPC_get_unique_event_times_and_counts <- function(df, expl_vars, subset_rules, t
time <- df[df[, censor_col] == 1, time_col]
print(time)
print(length(time) == 0)
if (length(time) < 2){
if (length(time) < 2) {
vtg::log$warn("< 2 events found in the data!")
return(data.frame(time = numeric(), Freq = numeric()))
}
Expand Down
16 changes: 9 additions & 7 deletions vtg.coxph/src/R/RPC_perform_iteration.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
RPC_perform_iteration <- function(df, subset_rules, expl_vars, time_col,
censor_col, beta, unique_event_times,
types = NULL, extend_data = TRUE) {
# Data pre-processing specific to EURACAN
if (extend_data){
df <- vtg.preprocessing::extend_data(df)
}
# Data pre-processing and filtering specific to EURACAN
df <- tryCatch(
vtg.preprocessing::subset_data(df, subset_rules),
{
if (extend_data) {
df <- vtg.preprocessing::extend_data(df)
}
df <- vtg.preprocessing::subset_data(df, subset_rules)
df
},
error = function(e) {
return(vtg::error_format(conditionMessage(e)))
vtg::error_format(conditionMessage(e))
}
)

if (!is.null(df$error)) {
vtg::log$error(df$error)
return(df)
Expand Down

0 comments on commit 16cd060

Please sign in to comment.