From fe17723416d8199989f5702876a603fdc3ea480e Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Tue, 15 Oct 2024 13:48:19 -0500 Subject: [PATCH] PopED fix --- NEWS.md | 3 +++ R/poped.R | 5 ++++- tests/testthat/test-poped.R | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index d9fd2797..8fa3f358 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ * Fix bug where `PopED` could error with certain `dvid` values +* Fix bug where if/else clauses in the model could cause the model to + not predict the values correctly. + # babelmixr2 0.1.4 * Added experimental `PopED` integration diff --git a/R/poped.R b/R/poped.R index eb04d817..fd06dc0a 100644 --- a/R/poped.R +++ b/R/poped.R @@ -825,7 +825,10 @@ rxUiGet.popedRxmodelBase <- function(x, ...) { logical(1), USE.NAMES = FALSE)) .mod <- .mod[.w] .errDf <- .iniDf[!is.na(.iniDf$err), ,drop=FALSE] - + # remove if/else so extra lhs statements are not hanging around + .mod <- str2lang(paste0("{", rxode2::.rxPrune(as.call(c(quote(`{`), .mod))), "}")) + .mod <- lapply(seq_along(.mod)[-1], + function(i) { .mod[[i]]}) .mod <- lapply(seq_along(.mod), function(i) { .cur <- .mod[[i]] diff --git a/tests/testthat/test-poped.R b/tests/testthat/test-poped.R index 9752499d..ce53ad11 100644 --- a/tests/testthat/test-poped.R +++ b/tests/testthat/test-poped.R @@ -622,5 +622,6 @@ if (requireNamespace("PopED", quietly=TRUE)) { p <- pheno() expect_equal(eval(.popedRxModel(p))$lhs, c("rx_pred_", "rx_r_")) + }) }