Skip to content

Commit

Permalink
fixing out-of-bounds error for list_list_perf[[idx]]
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonfparil committed Dec 20, 2024
1 parent dcd314c commit 327ea2c
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions R/cross_validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -755,17 +755,17 @@ fn_cross_validation_within_population = function(list_merged, n_folds=10, n_reps
)
if (methods::is(list_perf, "gpError")) {
cat(list_perf@message)
list_perf = NULL
} else {
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
}
### Concatenate performances
df_metrics = NULL
df_y_validation = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.na(list_perf)) {
if (is.na(utils::head(list_perf[[1]], n=1)[1])) {
next
}
if (is.na(utils::head(list_perf$df_metrics, n=1)[1]) | is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
Expand Down Expand Up @@ -1055,17 +1055,17 @@ fn_cross_validation_across_populations_bulk = function(list_merged, n_folds=10,
)
if (methods::is(list_perf, "gpError")) {
cat(list_perf@message)
list_perf = NULL
} else {
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
}
### Concatenate performances
METRICS_ACROSS_POP_BULK = NULL
YPRED_ACROSS_POP_BULK = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.na(list_perf)) {
if (is.na(utils::head(list_perf[[1]], n=1)[1])) {
next
}
if (is.na(utils::head(list_perf$df_metrics, n=1)[1]) | is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
Expand Down Expand Up @@ -1333,17 +1333,17 @@ fn_cross_validation_across_populations_pairwise = function(list_merged,
)
if (methods::is(list_perf, "gpError")) {
cat(list_perf@message)
list_perf = NULL
} else {
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
}
### Concatenate performances
df_metrics = NULL
df_y_validation = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.na(list_perf)) {
if (is.na(utils::head(list_perf[[1]], n=1)[1])) {
next
}
if (is.na(utils::head(list_perf$df_metrics, n=1)[1]) | is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
Expand Down Expand Up @@ -1607,25 +1607,20 @@ fn_cross_validation_across_populations_lopo = function(list_merged,
verbose=verbose
)
if (methods::is(list_perf, "gpError")) {
error = chain(list_perf, methods::new("gpError",
code=338,
message=paste0(
"Error in cross_validation::fn_cross_validation_across_populations_lopo(...). ",
"Error running leave-one-population-out cross-validation at ",
"rep: ", list_cv_params$df_params$rep[i], ", ",
"fold: ", list_cv_params$df_params$fold[i], ", and ",
"model: ", list_cv_params$df_params$model[i], "."
)))
cat(error@message); return(error)
cat(list_perf@message)
} else {
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
eval(parse(text=paste0("list_list_perf$`", i, "` = list_perf")))
}
}
### Concatenate performances
df_metrics = NULL
df_y_validation = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.na(utils::head(list_perf[[1]], n=1)[1])) {
next
}
if (is.na(utils::head(list_perf$df_metrics, n=1)[1]) | is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
next
}
Expand Down

0 comments on commit 327ea2c

Please sign in to comment.