Error exposing cmdstanr functions

I’m trying expose some functions from my model but I keep getting an error. The below example code when compiled returns an error if foo1 is not commented out.

functions {
  int foo0(real x) {
    return 1;
  }
  
  vector foo1(real x) {
    return rep_vector(1.0, 2);
  }
  
  vector foo2() {
    return rep_vector(1.0, 2);
  }
}

This is what I get

> test_model <- cmdstan_model("src/test.stan", compile_standalone = TRUE)
Compiling Stan program...
Compiling standalone functions...
Error in 1:first_decl : NA/NaN argument
In addition: Warning message:
In readLines(stan_file) : incomplete final line found on 'src/test.stan'

Operating System: Mac M2 Pro 13.6
Interface Version: cmdstanr 0.6.1, cmdstan 2.33.1
Compiler/Toolkit: ?

Thank you!

I think this is a bug that was fixed recently on GitHub (we’ll do another release soon). Can you try this using the development version of cmdstanr from GitHub and see if that fixes it?

# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
1 Like

Yes, that fixes it! Thanks.

1 Like

Ok great, glad it’s working now. We’ll do another cmdstanr R release soon with this fix plus some major new features (e.g. new pathfinder and laplace methods).

1 Like