From fa55b94545eeb0fcbee2fc120c432225076fa449 Mon Sep 17 00:00:00 2001 From: Dylan Nielson Date: Wed, 27 May 2026 18:29:27 -0400 Subject: [PATCH 1/2] try to fix unary returns --- semTools/R/permuteMeasEq.R | 66 +++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/semTools/R/permuteMeasEq.R b/semTools/R/permuteMeasEq.R index c1a19ea..f4347e8 100644 --- a/semTools/R/permuteMeasEq.R +++ b/semTools/R/permuteMeasEq.R @@ -1412,22 +1412,37 @@ permuteOnce.mgcfa <- function(i, d, G, con, uncon, null, param, freeParam, availableArgs$con <- out0 if (exists("out1")) availableArgs$uncon <- out1 if (exists("out.null")) availableArgs$null <- out.null - AFI <- do.call(getAFIs, availableArgs) + # Wrap getAFIs so a failure doesn't kill the worker + AFI <- tryCatch( + do.call(getAFIs, availableArgs), + error = function(e) { + allAFIs <- c(AFIs, moreAFIs) + out <- rep(NA_real_, sum(!is.na(allAFIs))) + names(out) <- allAFIs[!is.na(allAFIs)] + out + } + ) ## save max(MI) if !is.null(param) if (is.null(param)) { MI <- NULL } else { - MI <- max(do.call(getMIs, c(availableArgs, modelType = "mgcfa"))$X2) + # Wrap getMIs so a failure doesn't kill the worker + MI <- tryCatch( + max(do.call(getMIs, c(availableArgs, modelType = "mgcfa"))$X2), + error = function(e) NA_real_ + ) } ## anything extra? if (!is.null(extra)) { - extraArgs <- formals(extra) - neededArgs <- intersect(names(extraArgs), names(availableArgs)) - extraArgs <- do.call(c, lapply(neededArgs, function(nn) availableArgs[nn])) - extraOut <- do.call(extra, extraArgs) - ## coerce extraOut to data.frame - if (!is.list(extraOut)) extraOut <- as.list(extraOut) - extra.obs <- data.frame(extraOut) + extra.obs <- tryCatch({ + extraArgs <- formals(extra) + neededArgs <- intersect(names(extraArgs), names(availableArgs)) + extraArgs <- do.call(c, lapply(neededArgs, function(nn) availableArgs[nn])) + extraOut <- do.call(extra, extraArgs) + ## coerce extraOut to data.frame + if (!is.list(extraOut)) extraOut <- as.list(extraOut) + data.frame(extraOut) + }, error = function(e) NA) } else extra.obs <- data.frame(NULL) } options(warn = old_warn) @@ -1509,21 +1524,36 @@ permuteOnce.mimic <- function(i, d, G, con, uncon, null, param, freeParam, } else { availableArgs$con <- out0 if (exists("out.null")) availableArgs$null <- out.null - AFI <- do.call(getAFIs, availableArgs) + # Wrap get AFIs so errrors don't kill call + AFI <- tryCatch( + do.call(getAFIs, availableArgs), + error = function(e) { + allAFIs <- c(AFIs, moreAFIs) + out <- rep(NA_real_, sum(!is.na(allAFIs))) + names(out) <- allAFIs[!is.na(allAFIs)] + out + } + ) if (is.null(param)) { MI <- NULL } else { - MI <- max(do.call(getMIs, c(availableArgs, modelType = "mimic"))$X2) + # wrap getMIs so the whole thing doesn't crash if this fails + MI <- tryCatch( + max(do.call(getMIs, c(availableArgs, modelType = "mimic"))$X2), + error = function(e) NA_real_ + ) } ## anything extra? if (!is.null(extra)) { - extraArgs <- formals(extra) - neededArgs <- intersect(names(extraArgs), names(availableArgs)) - extraArgs <- do.call(c, lapply(neededArgs, function(nn) availableArgs[nn])) - extraOut <- do.call(extra, extraArgs) - ## coerce extraOut to data.frame - if (!is.list(extraOut)) extraOut <- as.list(extraOut) - extra.obs <- data.frame(extraOut) + extra.obs <- tryCatch({ + extraArgs <- formals(extra) + neededArgs <- intersect(names(extraArgs), names(availableArgs)) + extraArgs <- do.call(c, lapply(neededArgs, function(nn) availableArgs[nn])) + extraOut <- do.call(extra, extraArgs) + ## coerce extraOut to data.frame + if (!is.list(extraOut)) extraOut <- as.list(extraOut) + data.frame(extraOut) + }, error = function(e) NA) } else extra.obs <- data.frame(NULL) } options(warn = old_warn) From db294f2825062cddf18f6b5462f06b42ffb0044f Mon Sep 17 00:00:00 2001 From: Dylan Nielson Date: Wed, 27 May 2026 19:16:24 -0400 Subject: [PATCH 2/2] clean typos --- semTools/R/permuteMeasEq.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/semTools/R/permuteMeasEq.R b/semTools/R/permuteMeasEq.R index f4347e8..77dde3c 100644 --- a/semTools/R/permuteMeasEq.R +++ b/semTools/R/permuteMeasEq.R @@ -1524,7 +1524,7 @@ permuteOnce.mimic <- function(i, d, G, con, uncon, null, param, freeParam, } else { availableArgs$con <- out0 if (exists("out.null")) availableArgs$null <- out.null - # Wrap get AFIs so errrors don't kill call + # Wrap getAFIs so errors don't kill worker AFI <- tryCatch( do.call(getAFIs, availableArgs), error = function(e) { @@ -1537,7 +1537,7 @@ permuteOnce.mimic <- function(i, d, G, con, uncon, null, param, freeParam, if (is.null(param)) { MI <- NULL } else { - # wrap getMIs so the whole thing doesn't crash if this fails + # wrap getMIs so errors don't kill worker MI <- tryCatch( max(do.call(getMIs, c(availableArgs, modelType = "mimic"))$X2), error = function(e) NA_real_