cmdstanr icon indicating copy to clipboard operation
cmdstanr copied to clipboard

include file not found

Open copernican opened this issue 3 years ago • 0 comments

Describe the bug It appears that the handling of #include statements/include_paths may have changed from 0.5.2 to 0.5.3. With 0.5.3, the example from #680 gives this error:

library(cmdstanr)
#> This is cmdstanr version 0.5.3
#> - CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
#> - CmdStan path: /home/sean_wilson/.cmdstan/cmdstan-2.30.1
#> - CmdStan version: 2.30.1

data_code <- "
  data {
    int N;
  }
  "
data_file <- write_stan_file(code = data_code, basename = "data.stan")

model_code <- "
  #include data.stan
  parameters {
    vector[N] y;
  }
  model {
    y ~ std_normal();
  }
  "

model_file <- write_stan_file(code = model_code)
mod <- cmdstan_model(model_file, include_paths = dirname(data_file))
#> Syntax error in '/tmp/Rtmp6K52UA/model-2f3e47a3b4af.stan', line 2, column 2, include error:
#>    -------------------------------------------------
#>      1:  
#>      2:    #include data.stan
#>            ^
#>      3:    parameters {
#>      4:      vector[N] y;
#>    -------------------------------------------------
#> 
#> Could not find include file data.stan in specified include paths.
#> make: *** [/tmp/Rtmp6K52UA/model-2f3e47a3b4af.hpp] Error 1
#> Error: An error occured during compilation! See the message above for more information.

Under 0.5.2, it compiles fine.

library(cmdstanr)
#> This is cmdstanr version 0.5.2
#> - CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
#> - CmdStan path: /home/sean_wilson/.cmdstan/cmdstan-2.30.1
#> - CmdStan version: 2.30.1

data_code <- "
  data {
    int N;
  }
  "
data_file <- write_stan_file(code = data_code, basename = "data.stan")

model_code <- "
  #include data.stan
  parameters {
    vector[N] y;
  }
  model {
    y ~ std_normal();
  }
  "

model_file <- write_stan_file(code = model_code)
mod <- cmdstan_model(model_file, include_paths = dirname(data_file))
mod$exe_file()
#> [1] "/tmp/Rtmpz2t7Q8/model_00252e81bad3382f6acdbe052a2f2912"

Expected behavior The expected behavior is that the #include statement works as in 0.5.2.

Operating system Ubuntu 18.04.6

CmdStanR version number 0.5.3

copernican avatar Aug 08 '22 15:08 copernican