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 #1114

Closed sbfnk closed 4 months ago

sbfnk commented 4 months ago

Summary:

As a follow-up to #1093 and #1098 using expose_stan_functions can still cause unspecific errors sometimes.

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.32.5 (Stan version 2.32.2)
#> 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 variable1, real variable2, real long_variable_name) {} }'

## 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 2024-02-08 with reprex v2.1.0

Current Output:

An error.

Expected Output:

No error.

RStan Version:

Latest develop (277167c4): 2.33.1.9000

R Version:

R version 4.3.2 (2023-10-31)

Operating System:

macOS 14.3