Hi all,
I’m developing a package based on rstan/stan. There are some functions I’d like to pull out of .stan files and use from within the package (though, maybe not exported from the namespace; just internal functions to compute certain quantities from the posterior without using standalone gqs or inflating the model output size).
I cannot figure out how to do this properly for a package. I tried using expose_stan_functions, with cacheDir specified, and dropping the generated .cpp file(s) into src/, and running compileAttributes. However, it throws an error when building the package.
317 In file included from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/as.h:25:0,
318 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/RcppCommon.h:168,
319 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include/RcppEigenForward.h:26,
320 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include/RcppEigen.h:25,
321 from RcppExports.cpp:4:
322 /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/internal/Exporter.h: In instantiation of ‘Rcpp::traits::Exporter<T>::Exporter(SEXP) [with T = std::basic_ostream<char>*; SEXP = SEXPREC*]’:
323 /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/as.h:87:41: required from ‘T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag) [with T = std::basic_ostream<char>*; SEXP = SEXPREC*]’
324 /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/as.h:152:31: required from ‘T Rcpp::as(SEXP) [with T = std::basic_ostream<char>*; SEXP = SEXPREC*]’
325 /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/InputParameter.h:34:43: required from ‘Rcpp::InputParameter<T>::operator T() [with T = std::basic_ostream<char>*]’
326 RcppExports.cpp:18:57: required from here
327 /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/internal/Exporter.h:31:31: error: cannot convert ‘SEXP {aka SEXPREC*}’ to ‘std::basic_ostream<char>*’ in initialization
328 Exporter( SEXP x ) : t(x){}
329 ^
330 In file included from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/Rcpp/r/headers.h:64:0,
331 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include/RcppCommon.h:29,
332 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include/RcppEigenForward.h:26,
333 from /home/srmart/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include/RcppEigen.h:25,
334 from RcppExports.cpp:4:
335 ls.h:184:16: note: class type ‘SEXPREC’ is incomplete
336 typedef struct SEXPREC *SEXP;
337 ^~~~~~~
338 /usr/lib/R/etc/Makeconf:176: recipe for target 'RcppExports.o' failed
339 make: *** [RcppExports.o] Error 1
340 ERROR: compilation failed for package ‘omegad’
341 * removing ‘/home/srmart/R/x86_64-pc-linux-gnu-library/3.6/omegad’
342 * restoring previous ‘/home/srmart/R/x86_64-pc-linux-gnu-library/3.6/omegad’
343 Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
344 System command error
Any ideas? Or is there an updated step-by-step for how to use defined stan functions in a package?