Skip to content

Commit

Permalink
Merge pull request #1052 from stan-dev/fix-expose-dryRun
Browse files Browse the repository at this point in the history
`rstan`: Fix `expose_stan_functions` with dryRun
  • Loading branch information
hsbadr committed Mar 20, 2023
2 parents 7aca25b + db404cf commit 84e4b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rstan/rstan/R/expose_stan_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions rstan/rstan/tests/testthat/test-expose_dryRun.R
Original file line number Diff line number Diff line change
@@ -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))
})

0 comments on commit 84e4b24

Please sign in to comment.