stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.02k stars 264 forks source link

`expose_stan_functions` still sometimes fails with `..._lp` functions in rstan 2.26 #1098

Closed sbfnk closed 9 months ago

sbfnk commented 9 months ago

Summary:

As a follow-up to #1093 I still have this problem in some instances. I think it's because we don't know in advance where line breaks will be inserted.

Description:

expose_stan_function yields an unspecific error sometimes when used on ..._lp functions.

Reproducible Steps:

library("rstan")
#> Loading required package: StanHeaders
#> 
#> rstan version 2.33.1.9000 (Stan version 2.33.0)
#> For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores()).
#> To avoid recompilation of unchanged Stan programs, we recommend calling
#> rstan_options(auto_write = TRUE)
#> For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
#> change `threads_per_chain` option:
#> rstan_options(threads_per_chain = 1)

## make temporary directory
tmpdir <- tempdir()

## definfe test stan function
stan_function <- 'functions{ void test(real variable) {} }'
stan_function_lp <- 'functions{ void test_lp(real variable) {} }'

## write stan function to file
writeLines(stan_function, file.path(tmpdir, "test.stan"))
writeLines(stan_function_lp, file.path(tmpdir, "test_lp.stan"))

## compile stan function
expose_stan_functions(file.path(tmpdir, "test.stan"))
message("Success")
#> Success
expose_stan_functions(file.path(tmpdir, "test_lp.stan"))
#> 
#> WARNING: The tools required to build C++ code for R were not found.
#> 
#> Please install Command Line Tools for XCode (or equivalent).
#> Error in expose_stan_functions(file.path(tmpdir, "test_lp.stan")): Compilation failed!

Created on 2023-10-05 with reprex v2.0.2

Current Output:

An error.

Expected Output:

No error.

RStan Version:

Latest develop (a6dd8d1729f85a63b37fd47aed46cefe7eb94679): 2.33.1.9000

R Version:

R version 4.3.1 (2023-06-16)

Operating System:

OS X 14.0