From 0b4436fa883f42f3af4baa4c5ab0ac9dfb861b35 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Wed, 1 Nov 2023 18:08:23 -0500 Subject: [PATCH] Fix symengine compiled user functions --- R/symengine.R | 2 +- tests/testthat/test-udf.R | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/symengine.R b/R/symengine.R index de69e48d1..16de6f88b 100644 --- a/R/symengine.R +++ b/R/symengine.R @@ -2247,7 +2247,7 @@ rxS <- function(x, doConst = TRUE, promoteLinSens = FALSE, envir=parent.frame()) .env$rx_hi_ <- symengine::S("1") if (!is.null(rxode2parse::.rxSEeqUsr())) { sapply(names(rxode2parse::.rxSEeqUsr()), function(x) { - assign(.rxFunction(x), x, envir = .env) + assign(x, .rxFunction(x), envir = .env) }) } ## EulerGamma=0.57721566490153286060651209008240243104215933593992 diff --git a/tests/testthat/test-udf.R b/tests/testthat/test-udf.R index 32dabdd7e..09e32f817 100644 --- a/tests/testthat/test-udf.R +++ b/tests/testthat/test-udf.R @@ -295,11 +295,19 @@ rxTest({ test_that("symengine load", { mod <- "tke=THETA[1];\nprop.sd=THETA[2];\neta.ke=ETA[1];\nke=gg(tke,exp(eta.ke));\nipre=gg(10,exp(-ke*t));\nlipre=log(ipre);\nrx_yj_~2;\nrx_lambda_~1;\nrx_low_~0;\nrx_hi_~1;\nrx_pred_f_~ipre;\nrx_pred_~rx_pred_f_;\nrx_r_~(rx_pred_f_*prop.sd)^2;\n" + gg <- function(x, y) { - PreciseSums::psProd(c(x, y)) + x * y } - rxS(mod, TRUE, TRUE) + expect_error(rxS(mod, TRUE, TRUE), NA) + + rxFun(gg) + + rm(gg) + + expect_error(rxS(mod, TRUE, TRUE), NA) + }) })