Binary packages for StanHeaders 2.21.0-6 are now on CRAN. You should install it, particularly on Windows, particularly if you are having problems with spaces in the paths to files when it tries to compile a Stan program.
StanHeaders has historically not contained any R functions and is just used by RStan and a couple of other packages to compile things. However, in 2.21.x it now has (unexported) functions StanHeaders:::CxxFlags()
and StanHeaders:::LdFlags()
that can be called from Makevars files in other packages to correctly compile. The rstantools package does this automatically, so you should only need to do it manually if you used rstantools 1.x to originally create your package.
StanHeaders 2.21.0-6 now has its first exported R function, which is called stanFunction
and is mostly a wrapper around Rcpp::cxxFunction
that is specialized for compiling and exposing (most) functions in the Stan Math Library. The main difference is that you also need to pass the corresponding arguments (by position) to that function in the Stan Math Library the first time you compile it within a R session. After it has been compiled once, a R function with the same name as the Stan Math function is available in the global (by default) environment and it can be called with different values (but the same types) of its arguments. There is an example that you would need to call with run.dontrun = TRUE
because it takes about 15 seconds to compile and expose a function from the Stan Math Library. But the gist of it is is
library(StanHeaders)
stanFunction("log_sum_exp", x = exp(1), y = pi) # compiles and returns 3.64
log_sum_exp(x = pi, y = exp(1)) # log_sum_exp exists now and returns 3.64