Error compiling own fuctions

When trying to compile my own functions I am getting the following error:
make: *** [/usr/lib/R/etc/Makeconf:177: file18e76c0c9bb1.o] Error 1
Error in Rcpp::sourceCpp(code = paste(code, collapse = “\n”), …) :
Error 1 occurred building shared library.
Error in sink(type = “output”) : invalid connection

model_code<-
  '
  functions{
  real diff(real a,real b){
    return a-b;
  }
  real myvec(real a,real b){
   return pow(a,b);
  }
  
  }
    '
rstan::expose_stan_functions(rstan::stanc(model_code = model_code))

I can perform MCMC sampling writing a .stan file with the relevant blocks but this issue is arising whenever I try to compile my own functions.

Welcome to the Stan forums and sorry you’re getting an error. I don’t know enough about what expose_stan_functions() is doing internally to know why your functions would work in a Stan program but not via expose_stan_function(). @bgoodri Do you know what’s up here?

@hasibul212003 In the meantime, can you share details about your configuration? What operating system do you have? Which version of rstan are you using?

HI thanks for your response. I actually uninstalled my rstan and reinstalled it and the error just went away.
1st installation was via terminal sudo apt install r-cran-rstan.
2nd time I installed it from source: install.packages(“rstan”,type=“source”) & the error just went away after that.

1 Like