From db404cf67b996fcce9db7f9937b7ebcae926e898 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 20 Mar 2023 07:22:22 +0200 Subject: [PATCH] Fix expose_functions dryrun, add test --- rstan/rstan/R/expose_stan_functions.R | 2 +- rstan/rstan/tests/testthat/test-expose_dryRun.R | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 rstan/rstan/tests/testthat/test-expose_dryRun.R diff --git a/rstan/rstan/R/expose_stan_functions.R b/rstan/rstan/R/expose_stan_functions.R index ca9947258..1cda87b7b 100644 --- a/rstan/rstan/R/expose_stan_functions.R +++ b/rstan/rstan/R/expose_stan_functions.R @@ -102,7 +102,6 @@ expose_stan_functions <- function(stanmodel, includes = NULL, # workaround for packages with src/install.libs.R identical(Sys.getenv("WINDOWS"), "TRUE") && !identical(Sys.getenv("R_PACKAGE_SOURCE"), "") ) - if (inherits(compiled, "try-error")) stop("Compilation failed!") if (!isTRUE(show_compiler_warnings)) { sink(type = "output") close(zz) @@ -116,6 +115,7 @@ expose_stan_functions <- function(stanmodel, includes = NULL, } DOTS <- list(...) if (isTRUE(DOTS$dryRun)) return(code) + if (inherits(compiled, "try-error")) stop("Compilation failed!") ENV <- DOTS$env if (is.null(ENV)) ENV <- globalenv() for (x in compiled$functions) { diff --git a/rstan/rstan/tests/testthat/test-expose_dryRun.R b/rstan/rstan/tests/testthat/test-expose_dryRun.R new file mode 100644 index 000000000..eb4775ac2 --- /dev/null +++ b/rstan/rstan/tests/testthat/test-expose_dryRun.R @@ -0,0 +1,10 @@ +test_that("expose_functions works with dryRun", { + funcode <- " + functions { + real rtn_real(real x) { + return x; + } + }" + + expect_no_error(expose_stan_functions(stanc(model_code = funcode), dryRun = TRUE)) +})