Compilation error with {rstantools} on Mac OS ("'stan/version.hpp' file not found")

This question is similar to Rstantools: Compilation error under Mac OSX, but it persists with rstantools version 2.2.0 (current CRAN at the time of writing). Also posted at rstantools cannot find `stan/version.hpp` · Issue #97 · stan-dev/rstantools · GitHub.

Operating System: Mac OS Monterey (12.5.1)
Interface Version: rstantools 2.2.0, rstan 2.21.5, StanHeaders 2.21.0.7.
Compiler/Toolkit: Apple clang version 13.1.6 (clang-1316.0.21.2.5), R 4.2.0

Original post

I am developing a package with a stan model and using rstantools for configuration. On my MacBook, R cannot find stan/version.hpp when it tries to compile the package. I think the file may belong in /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include, but it is not on my system after installing StanHeaders 2.21.0-7 (either source or binary) and upgrading to rstan 2.21.5 and rstantools 2.2.0.

list.files("/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan")
#> [1] "math"     "math.hpp"

Models like the one below still compile successfully with rstan.

model_code <- "
data {
  real y;
}
parameters {
  real theta;
}
model {
  y ~ normal(theta, 1);
  theta ~ normal(0, 1);
}
"
model <- rstan::stan_model(model_code = model_code)
model
#>
#> > model
#> S4 class stanmodel 'f851b51190fe252f738e2d3974c697af' coded as follows:
#> 
#> data {
#>   real y;
#> }
#> parameters {
#>   real theta;
#> }
#> model {
#>   y ~ normal(theta, 1);
#>   theta ~ normal(0, 1);
#> }

I followed the usual steps to build this model into an R package.

setwd(fs::dir_create(tempfile()))
usethis::create_package("testpackage", open = FALSE)
setwd("testpackage")
roxygen <- c(
  "#' @import Rcpp methods",
  "#' @importFrom rstan sampling",
  "#' @useDynLib testpackage, .registration = TRUE",
  "NULL"
)
fs::dir_create("R")
writeLines(roxygen, "R/roxygen.R")
devtools::document()
fs::dir_create(file.path("inst", "stan"))
writeLines(model_code, file.path("inst", "stan", "model.stan"))
rstantools::use_rstan()
install.packages(".", type = "source", repos = NULL)

I ran into this error during compilation when I try to install the package.

In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 
      'stan/version.hpp' file not found
#include <stan/version.hpp>
         ^~~~~~~~~~~~~~~~~~
14 warnings and 1 error generated.
make: *** [stanExports_model.o] Error 1
ERROR: compilation failed for package ‘testpackage’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
Warning message:
In install.packages(".", type = "source", repos = NULL) :
  installation of package ‘.’ had non-zero exit status

This issue looks similar to #47, but it has been long enough since How to update a package that has StanHeaders and rstan in its LinkingTo and How to update a package that has StanHeaders and rstan in its LinkingTo, part II - #4 by bgoodri that the package Makevars written by rstantools. And I do not have a "~/.R/Makevars".

> writeLines(readLines("src/Makevars"))
# Generated by rstantools.  Do not edit by hand.

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= 2.26, '-DUSE_STANC3',''))")
PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error $(STANC_FLAGS)
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX14
Session info
  • Mac OS 12.3.1
  • 2018 15-inch MacBook Pro
  • Using the Mac Terminal (not RStudio, VSCode, or other IDE).
$ gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testpackage_0.0.0.9000

loaded via a namespace (and not attached):
 [1] pillar_1.7.0      compiler_4.2.0    prettyunits_1.1.1 remotes_2.4.2    
 [5] tools_4.2.0       digest_0.6.29     testthat_3.1.4    pkgbuild_1.3.1   
 [9] pkgload_1.2.4     memoise_2.0.1     lifecycle_1.0.1   tibble_3.1.7     
[13] pkgconfig_2.0.3   rlang_1.0.2       cli_3.3.0         rstudioapi_0.13  
[17] xfun_0.31         fastmap_1.1.0     withr_2.5.0       stringr_1.4.0    
[21] roxygen2_7.1.2    xml2_1.3.3        knitr_1.39        desc_1.4.1       
[25] fs_1.5.2          vctrs_0.4.1       devtools_2.4.3    rprojroot_2.0.3  
[29] glue_1.6.2        R6_2.5.1          processx_3.5.3    fansi_1.0.3      
[33] sessioninfo_1.2.2 purrr_0.3.4       callr_3.7.0       magrittr_2.0.3   
[37] rstantools_2.2.0  ps_1.7.0          ellipsis_0.3.2    usethis_2.1.5    
[41] utf8_1.2.2        stringi_1.7.6     cachem_1.0.6      crayon_1.5.1     
[45] brio_1.1.3

The first thing to check is that the file is present in the StanHeaders package (it’s in a slightly different directory to the one you’ve already checked). Can you post the output from:

list.files("/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan")

Also, can you post the full output from the install.packages command, so we can see the arguments and include paths being passed to the compiler?

Looks like version.hpp is in that folder:

list.files("/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan")
#> [1] "analyze"      "callbacks"    "command"      "io"           "lang"        
#> [6] "mcmc"         "model"        "optimization" "services"     "variational" 
#> [11] "version.hpp" 

And here is the output from install.packages():

Complete compilation log
* installing *source* package ‘testpackage’ ...
** using staged installation
** libs


clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeader/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/CholmodSupport:45:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/KroneckerProduct:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:39:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/Polynomials:135:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:40:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
18 warnings generated.


clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeader/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS   -fPIC  -Wall -g -O2  -c stanExports_model.cc -o stanExports_model.o
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: 
      pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 
      'stan/version.hpp' file not found
#include <stan/version.hpp>
         ^~~~~~~~~~~~~~~~~~
14 warnings and 1 error generated.
make: *** [stanExports_model.o] Error 1
ERROR: compilation failed for package ‘testpackage’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
Warning message:
In install.packages(".", type = "source", repos = NULL) :
  installation of package ‘.’ had non-zero exit status

It looks like a configuration issue, where StanHeaders is mis-spelled. In the compilation arguments it has:

 -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeader/include/src" 

Where StanHeaders is missing the s at the end, which is why the compiler can’t find the file

Rather than creating the skeleton using usethis, can you use the rstantools::rstan_create_package() function and then add your Stan model?

But here’s compilation output for a different package, it looks like this time /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src is included and contains stan/version.hpp on my machine.

* installing *source* package ‘CENSORED’ ...
** using staged installation
** libs


clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS   -fPIC  -Wall -g -O2  -c stanExports_CENSORED.cc -o stanExports_CENSORED.o
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 'stan/version.hpp' file not found
#include <stan/version.hpp>
         ^~~~~~~~~~~~~~~~~~
14 warnings and 1 error generated.
make: *** [stanExports_CENSORED.o] Error 1
ERROR: compilation failed for package ‘CENSORED’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/CENSORED’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/CENSORED’
Warning in install.packages :
  installation of package ‘.’ had non-zero exit status

Yeah, that’s a useful thing to try:

setwd(fs::dir_create(tempfile()))
rstantools::rstan_create_package("testpackage", open = FALSE)
setwd("testpackage")
model_code <- "
data {
  real y;
}
parameters {
  real theta;
}
model {
  y ~ normal(theta, 1);
  theta ~ normal(0, 1);
}
"
writeLines(model_code, file.path("inst", "stan", "model.stan"))
install.packages(".", type = "source", repos = NULL)

Looks like the include path is spelled correctly this time but I get the same compilation issue.

> setwd(fs::dir_create(tempfile()))
> rstantools::rstan_create_package("testpackage", open = FALSE)
Creating package skeleton for package: testpackage
Package: testpackage
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to
    pick a license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
Creating inst/stan/include directory ...
Creating inst/include directory ...
Creating src directory ...
Updating DESCRIPTION ...
Adding 'configure' files ...

Next, add the following lines (e.g., via <package-name>-package.R if using roxygen) to your NAMESPACE:

import(Rcpp)
import(methods)
importFrom(rstan, sampling)
useDynLib(testpackage, .registration = TRUE)

Done.
Adding testpackage-package.R file ...
Configuring Stan compile and module export instructions ...
Further Stan-specific steps are described in 'testpackage/Read-and-delete-me'.
> setwd("testpackage")
> model_code <- "
+ data {
+   real y;
+ }
+ parameters {
+   real theta;
+ }
+ model {
+   y ~ normal(theta, 1);
+   theta ~ normal(0, 1);
+ }
+ "
> writeLines(model_code, file.path("inst", "stan", "model.stan"))
> install.packages(".", type = "source", repos = NULL)
* installing *source* package ‘testpackage’ ...
** using staged installation
** libs


clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/CholmodSupport:45:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/KroneckerProduct:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:39:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/Polynomials:135:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:40:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
18 warnings generated.


clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS   -fPIC  -Wall -g -O2  -c stanExports_model.cc -o stanExports_model.o
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_model.cc:5:
In file included from ./stanExports_model.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 'stan/version.hpp' file not found
#include <stan/version.hpp>
         ^~~~~~~~~~~~~~~~~~
14 warnings and 1 error generated.
make: *** [stanExports_model.o] Error 1
ERROR: compilation failed for package ‘testpackage’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/testpackage’
Warning in install.packages :
  installation of package ‘.’ had non-zero exit status

The next thing to check is whether this is an rstantools issue or a system issue. Are you able to install rstan from source and run the package example model?

example(stan_model, package = "rstan", run.dontrun = TRUE)

Looks like install.packages("rstan", type = "source") completed without errors. Then in a new R session, example(stan_model, package = "rstan", run.dontrun = TRUE) compiled and ran as expected.

Can you run the example with verbose=TRUE and post the output? Then we can see how the compilation arguments differ

Certainly:

> example(stan_model, package = "rstan", run.dontrun = TRUE, verbose = TRUE)
Found file = ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/help/stan_model’ 
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.5, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
'envir' chosen:<environment: R_GlobalEnv>
encoding = "UTF-8" chosen
--> parsed 4 expressions; now eval(.)ing them:
has srcrefs:
List of 4
 $ : 'srcref' int [1:8] 8 1 8 84 1 84 8 8
  ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7fa1d6e643c8> 
 $ : 'srcref' int [1:8] 9 1 9 56 1 56 9 9
  ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7fa1d6e643c8> 
 $ : 'srcref' int [1:8] 10 1 10 45 1 45 10 10
  ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7fa1d6e643c8> 
 $ : 'srcref' int [1:8] 11 1 11 46 1 46 11 11
  ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7fa1d6e643c8> 

>>>> eval(expression_nr. 1 )
		 =================

stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
curr.fun: symbol <-
 .. after ‘expression(stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}')’

>>>> eval(expression_nr. 2 )
		 =================

stn_md> mod <- stan_model(model_code = stancode, verbose = TRUE)

TRANSLATING MODEL '16a540c6086086816528e4524def24d9' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '16a540c6086086816528e4524def24d9'.
COMPILING THE C++ CODE FOR MODEL '16a540c6086086816528e4524def24d9' NOW.
OS: x86_64, darwin17.0; rstan: 2.21.5; Rcpp: 1.0.9; inline: 0.3.19 
 >> setting environment variables: 
PKG_LIBS =  '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/' -ltbb
PKG_CPPFLAGS =   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 
 >> Program source :

   1 : 
   2 : // includes from the plugin
   3 : // [[Rcpp::plugins(cpp14)]]
   4 : 
   5 : 
   6 : // user includes
   7 : #include <Rcpp.h>
   8 : #include <rstan/io/rlist_ref_var_context.hpp>
   9 : #include <rstan/io/r_ostream.hpp>
  10 : #include <rstan/stan_args.hpp>
  11 : #include <boost/integer/integer_log2.hpp>
  12 : // Code generated by Stan version 2.21.0
  13 : 
  14 : #include <stan/model/model_header.hpp>
  15 : 
  16 : namespace model16662648ac334_16a540c6086086816528e4524def24d9_namespace {
  17 : 
  18 : using std::istream;
  19 : using std::string;
  20 : using std::stringstream;
  21 : using std::vector;
  22 : using stan::io::dump;
  23 : using stan::math::lgamma;
  24 : using stan::model::prob_grad;
  25 : using namespace stan::math;
  26 : 
  27 : static int current_statement_begin__;
  28 : 
  29 : stan::io::program_reader prog_reader__() {
  30 :     stan::io::program_reader reader;
  31 :     reader.add_event(0, 0, "start", "model16662648ac334_16a540c6086086816528e4524def24d9");
  32 :     reader.add_event(3, 1, "end", "model16662648ac334_16a540c6086086816528e4524def24d9");
  33 :     return reader;
  34 : }
  35 : 
  36 : class model16662648ac334_16a540c6086086816528e4524def24d9
  37 :   : public stan::model::model_base_crtp<model16662648ac334_16a540c6086086816528e4524def24d9> {
  38 : private:
  39 :         double y_mean;
  40 : public:
  41 :     model16662648ac334_16a540c6086086816528e4524def24d9(rstan::io::rlist_ref_var_context& context__,
  42 :         std::ostream* pstream__ = 0)
  43 :         : model_base_crtp(0) {
  44 :         ctor_body(context__, 0, pstream__);
  45 :     }
  46 : 
  47 :     model16662648ac334_16a540c6086086816528e4524def24d9(stan::io::var_context& context__,
  48 :         unsigned int random_seed__,
  49 :         std::ostream* pstream__ = 0)
  50 :         : model_base_crtp(0) {
  51 :         ctor_body(context__, random_seed__, pstream__);
  52 :     }
  53 : 
  54 :     void ctor_body(stan::io::var_context& context__,
  55 :                    unsigned int random_seed__,
  56 :                    std::ostream* pstream__) {
  57 :         typedef double local_scalar_t__;
  58 : 
  59 :         boost::ecuyer1988 base_rng__ =
  60 :           stan::services::util::create_rng(random_seed__, 0);
  61 :         (void) base_rng__;  // suppress unused var warning
  62 : 
  63 :         current_statement_begin__ = -1;
  64 : 
  65 :         static const char* function__ = "model16662648ac334_16a540c6086086816528e4524def24d9_namespace::model16662648ac334_16a540c6086086816528e4524def24d9";
  66 :         (void) function__;  // dummy to suppress unused var warning
  67 :         size_t pos__;
  68 :         (void) pos__;  // dummy to suppress unused var warning
  69 :         std::vector<int> vals_i__;
  70 :         std::vector<double> vals_r__;
  71 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  72 :         (void) DUMMY_VAR__;  // suppress unused var warning
  73 : 
  74 :         try {
  75 :             // initialize data block variables from context__
  76 :             current_statement_begin__ = 1;
  77 :             context__.validate_dims("data initialization", "y_mean", "double", context__.to_vec());
  78 :             y_mean = double(0);
  79 :             vals_r__ = context__.vals_r("y_mean");
  80 :             pos__ = 0;
  81 :             y_mean = vals_r__[pos__++];
  82 : 
  83 : 
  84 :             // initialize transformed data variables
  85 :             // execute transformed data statements
  86 : 
  87 :             // validate transformed data
  88 : 
  89 :             // validate, set parameter ranges
  90 :             num_params_r__ = 0U;
  91 :             param_ranges_i__.clear();
  92 :             current_statement_begin__ = 1;
  93 :             num_params_r__ += 1;
  94 :         } catch (const std::exception& e) {
  95 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
  96 :             // Next line prevents compiler griping about no return
  97 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
  98 :         }
  99 :     }
 100 : 
 101 :     ~model16662648ac334_16a540c6086086816528e4524def24d9() { }
 102 : 
 103 : 
 104 :     void transform_inits(const stan::io::var_context& context__,
 105 :                          std::vector<int>& params_i__,
 106 :                          std::vector<double>& params_r__,
 107 :                          std::ostream* pstream__) const {
 108 :         typedef double local_scalar_t__;
 109 :         stan::io::writer<double> writer__(params_r__, params_i__);
 110 :         size_t pos__;
 111 :         (void) pos__; // dummy call to supress warning
 112 :         std::vector<double> vals_r__;
 113 :         std::vector<int> vals_i__;
 114 : 
 115 :         current_statement_begin__ = 1;
 116 :         if (!(context__.contains_r("y")))
 117 :             stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__());
 118 :         vals_r__ = context__.vals_r("y");
 119 :         pos__ = 0U;
 120 :         context__.validate_dims("parameter initialization", "y", "double", context__.to_vec());
 121 :         double y(0);
 122 :         y = vals_r__[pos__++];
 123 :         try {
 124 :             writer__.scalar_unconstrain(y);
 125 :         } catch (const std::exception& e) {
 126 :             stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__());
 127 :         }
 128 : 
 129 :         params_r__ = writer__.data_r();
 130 :         params_i__ = writer__.data_i();
 131 :     }
 132 : 
 133 :     void transform_inits(const stan::io::var_context& context,
 134 :                          Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
 135 :                          std::ostream* pstream__) const {
 136 :       std::vector<double> params_r_vec;
 137 :       std::vector<int> params_i_vec;
 138 :       transform_inits(context, params_i_vec, params_r_vec, pstream__);
 139 :       params_r.resize(params_r_vec.size());
 140 :       for (int i = 0; i < params_r.size(); ++i)
 141 :         params_r(i) = params_r_vec[i];
 142 :     }
 143 : 
 144 : 
 145 :     template <bool propto__, bool jacobian__, typename T__>
 146 :     T__ log_prob(std::vector<T__>& params_r__,
 147 :                  std::vector<int>& params_i__,
 148 :                  std::ostream* pstream__ = 0) const {
 149 : 
 150 :         typedef T__ local_scalar_t__;
 151 : 
 152 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 153 :         (void) DUMMY_VAR__;  // dummy to suppress unused var warning
 154 : 
 155 :         T__ lp__(0.0);
 156 :         stan::math::accumulator<T__> lp_accum__;
 157 :         try {
 158 :             stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 159 : 
 160 :             // model parameters
 161 :             current_statement_begin__ = 1;
 162 :             local_scalar_t__ y;
 163 :             (void) y;  // dummy to suppress unused var warning
 164 :             if (jacobian__)
 165 :                 y = in__.scalar_constrain(lp__);
 166 :             else
 167 :                 y = in__.scalar_constrain();
 168 : 
 169 :             // model body
 170 : 
 171 :             current_statement_begin__ = 1;
 172 :             lp_accum__.add(normal_log<propto__>(y, y_mean, 1));
 173 : 
 174 :         } catch (const std::exception& e) {
 175 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 176 :             // Next line prevents compiler griping about no return
 177 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 178 :         }
 179 : 
 180 :         lp_accum__.add(lp__);
 181 :         return lp_accum__.sum();
 182 : 
 183 :     } // log_prob()
 184 : 
 185 :     template <bool propto, bool jacobian, typename T_>
 186 :     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
 187 :                std::ostream* pstream = 0) const {
 188 :       std::vector<T_> vec_params_r;
 189 :       vec_params_r.reserve(params_r.size());
 190 :       for (int i = 0; i < params_r.size(); ++i)
 191 :         vec_params_r.push_back(params_r(i));
 192 :       std::vector<int> vec_params_i;
 193 :       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
 194 :     }
 195 : 
 196 : 
 197 :     void get_param_names(std::vector<std::string>& names__) const {
 198 :         names__.resize(0);
 199 :         names__.push_back("y");
 200 :     }
 201 : 
 202 : 
 203 :     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
 204 :         dimss__.resize(0);
 205 :         std::vector<size_t> dims__;
 206 :         dims__.resize(0);
 207 :         dimss__.push_back(dims__);
 208 :     }
 209 : 
 210 :     template <typename RNG>
 211 :     void write_array(RNG& base_rng__,
 212 :                      std::vector<double>& params_r__,
 213 :                      std::vector<int>& params_i__,
 214 :                      std::vector<double>& vars__,
 215 :                      bool include_tparams__ = true,
 216 :                      bool include_gqs__ = true,
 217 :                      std::ostream* pstream__ = 0) const {
 218 :         typedef double local_scalar_t__;
 219 : 
 220 :         vars__.resize(0);
 221 :         stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 222 :         static const char* function__ = "model16662648ac334_16a540c6086086816528e4524def24d9_namespace::write_array";
 223 :         (void) function__;  // dummy to suppress unused var warning
 224 : 
 225 :         // read-transform, write parameters
 226 :         double y = in__.scalar_constrain();
 227 :         vars__.push_back(y);
 228 : 
 229 :         double lp__ = 0.0;
 230 :         (void) lp__;  // dummy to suppress unused var warning
 231 :         stan::math::accumulator<double> lp_accum__;
 232 : 
 233 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 234 :         (void) DUMMY_VAR__;  // suppress unused var warning
 235 : 
 236 :         if (!include_tparams__ && !include_gqs__) return;
 237 : 
 238 :         try {
 239 :             if (!include_gqs__ && !include_tparams__) return;
 240 :             if (!include_gqs__) return;
 241 :         } catch (const std::exception& e) {
 242 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 243 :             // Next line prevents compiler griping about no return
 244 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 245 :         }
 246 :     }
 247 : 
 248 :     template <typename RNG>
 249 :     void write_array(RNG& base_rng,
 250 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 251 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
 252 :                      bool include_tparams = true,
 253 :                      bool include_gqs = true,
 254 :                      std::ostream* pstream = 0) const {
 255 :       std::vector<double> params_r_vec(params_r.size());
 256 :       for (int i = 0; i < params_r.size(); ++i)
 257 :         params_r_vec[i] = params_r(i);
 258 :       std::vector<double> vars_vec;
 259 :       std::vector<int> params_i_vec;
 260 :       write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
 261 :       vars.resize(vars_vec.size());
 262 :       for (int i = 0; i < vars.size(); ++i)
 263 :         vars(i) = vars_vec[i];
 264 :     }
 265 : 
 266 :     std::string model_name() const {
 267 :         return "model16662648ac334_16a540c6086086816528e4524def24d9";
 268 :     }
 269 : 
 270 : 
 271 :     void constrained_param_names(std::vector<std::string>& param_names__,
 272 :                                  bool include_tparams__ = true,
 273 :                                  bool include_gqs__ = true) const {
 274 :         std::stringstream param_name_stream__;
 275 :         param_name_stream__.str(std::string());
 276 :         param_name_stream__ << "y";
 277 :         param_names__.push_back(param_name_stream__.str());
 278 : 
 279 :         if (!include_gqs__ && !include_tparams__) return;
 280 : 
 281 :         if (include_tparams__) {
 282 :         }
 283 : 
 284 :         if (!include_gqs__) return;
 285 :     }
 286 : 
 287 : 
 288 :     void unconstrained_param_names(std::vector<std::string>& param_names__,
 289 :                                    bool include_tparams__ = true,
 290 :                                    bool include_gqs__ = true) const {
 291 :         std::stringstream param_name_stream__;
 292 :         param_name_stream__.str(std::string());
 293 :         param_name_stream__ << "y";
 294 :         param_names__.push_back(param_name_stream__.str());
 295 : 
 296 :         if (!include_gqs__ && !include_tparams__) return;
 297 : 
 298 :         if (include_tparams__) {
 299 :         }
 300 : 
 301 :         if (!include_gqs__) return;
 302 :     }
 303 : 
 304 : }; // model
 305 : 
 306 : }  // namespace
 307 : 
 308 : typedef model16662648ac334_16a540c6086086816528e4524def24d9_namespace::model16662648ac334_16a540c6086086816528e4524def24d9 stan_model;
 309 : 
 310 : #ifndef USING_R
 311 : 
 312 : stan::model::model_base& new_model(
 313 :         stan::io::var_context& data_context,
 314 :         unsigned int seed,
 315 :         std::ostream* msg_stream) {
 316 :   stan_model* m = new stan_model(data_context, seed, msg_stream);
 317 :   return *m;
 318 : }
 319 : 
 320 : #endif
 321 : 
 322 : 
 323 : 
 324 : #include <rstan_next/stan_fit.hpp>
 325 : 
 326 : struct stan_model_holder {
 327 :     stan_model_holder(rstan::io::rlist_ref_var_context rcontext,
 328 :                       unsigned int random_seed)
 329 :     : rcontext_(rcontext), random_seed_(random_seed)
 330 :      {
 331 :      }
 332 : 
 333 :    //stan::math::ChainableStack ad_stack;
 334 :    rstan::io::rlist_ref_var_context rcontext_;
 335 :    unsigned int random_seed_;
 336 : };
 337 : 
 338 : Rcpp::XPtr<stan::model::model_base> model_ptr(stan_model_holder* smh) {
 339 :   Rcpp::XPtr<stan::model::model_base> model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true);
 340 :   return model_instance;
 341 : }
 342 : 
 343 : Rcpp::XPtr<rstan::stan_fit_base> fit_ptr(stan_model_holder* smh) {
 344 :   return Rcpp::XPtr<rstan::stan_fit_base>(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true);
 345 : }
 346 : 
 347 : std::string model_name(stan_model_holder* smh) {
 348 :   return model_ptr(smh).get()->model_name();
 349 : }
 350 : 
 351 : RCPP_MODULE(stan_fit4model16662648ac334_16a540c6086086816528e4524def24d9_mod){
 352 :   Rcpp::class_<stan_model_holder>("stan_fit4model16662648ac334_16a540c6086086816528e4524def24d9")
 353 :   .constructor<rstan::io::rlist_ref_var_context, unsigned int>()
 354 :   .method("model_ptr", &model_ptr)
 355 :   .method("fit_ptr", &fit_ptr)
 356 :   .method("model_name", &model_name)
 357 :   ;
 358 : }
 359 : 
 360 : 
 361 : // declarations
 362 : extern "C" {
 363 : SEXP file16662118d2aa5( ) ;
 364 : }
 365 : 
 366 : // definition
 367 : SEXP file16662118d2aa5() {
 368 :  return Rcpp::wrap("16a540c6086086816528e4524def24d9");
 369 : }
make cmd is
  make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file16662118d2aa5.so' OBJECTS='file16662118d2aa5.o'

make would use
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c file16662118d2aa5.cpp -o file16662118d2aa5.o
if test  "zfile16662118d2aa5.o" != "z"; then \
	  echo clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o file16662118d2aa5.so file16662118d2aa5.o  '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/' -ltbb  -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	  clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o file16662118d2aa5.so file16662118d2aa5.o  '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/' -ltbb  -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	fi
curr.fun: symbol <-
 .. after ‘expression(mod <- stan_model(model_code = stancode, verbose = TRUE))’

>>>> eval(expression_nr. 3 )
		 =================

stn_md> fit <- sampling(mod, data = list(y_mean = 0))

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 1e-05 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 0.008416 seconds (Warm-up)
Chain 1:                0.007894 seconds (Sampling)
Chain 1:                0.01631 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 8e-06 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.08 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.007981 seconds (Warm-up)
Chain 2:                0.007783 seconds (Sampling)
Chain 2:                0.015764 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 6e-06 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 0.007682 seconds (Warm-up)
Chain 3:                0.007426 seconds (Sampling)
Chain 3:                0.015108 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 7e-06 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.07 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 0.007567 seconds (Warm-up)
Chain 4:                0.007266 seconds (Sampling)
Chain 4:                0.014833 seconds (Total)
Chain 4: 
curr.fun: symbol <-
 .. after ‘expression(fit <- sampling(mod, data = list(y_mean = 0)))’

>>>> eval(expression_nr. 4 )
		 =================

stn_md> fit2 <- sampling(mod, data = list(y_mean = 5))

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 6e-06 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 0.006271 seconds (Warm-up)
Chain 1:                0.006331 seconds (Sampling)
Chain 1:                0.012602 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 6e-06 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.00699 seconds (Warm-up)
Chain 2:                0.007083 seconds (Sampling)
Chain 2:                0.014073 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 2.6e-05 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.26 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 0.007717 seconds (Warm-up)
Chain 3:                0.006919 seconds (Sampling)
Chain 3:                0.014636 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL '16a540c6086086816528e4524def24d9' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 4e-06 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.04 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 0.007011 seconds (Warm-up)
Chain 4:                0.006167 seconds (Sampling)
Chain 4:                0.013178 seconds (Total)
Chain 4: 
curr.fun: symbol <-
 .. after ‘expression(fit2 <- sampling(mod, data = list(y_mean = 5)))’

Curiouser and curiouser! I still can’t reproduce locally on Windows or Linux, so I’ll unfortunately have to give you more debug steps sorry! The next thing to check is whether the rstantools makevars are the issue by setting them to the known-good values from the example() call above.

Can I get you to delete the configure and configure.win files, and create a src/Makevars file with the content:

PKG_LIBS =  '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/' -ltbb
PKG_CPPFLAGS =   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 

Also, make sure that the NAMESPACE file has been updated , otherwise you’ll run into shared object errors when installing. This is either handled automatically by roxygen or can be done manually:

setwd(fs::dir_create(tempfile()))
rstantools::rstan_create_package("testpackage", open = FALSE)
setwd("testpackage")
model_code <- "data { real y; } parameters { real theta; } model { y ~ normal(theta, 1); theta ~ normal(0, 1); }"
writeLines(model_code, file.path("inst", "stan", "model.stan"))
cat(c("import(Rcpp)", "import(methods)", "importFrom(rstan, sampling)", 
      "useDynLib(testpackage, .registration = TRUE)"),
    file = "NAMESPACE", append = FALSE, sep = "\n")
install.packages(".", type = "source", repo = NULL)

To double-check whether this is an rstantools and macos-specific issue, I made a GitHub actions run using the code block above on MacOS 12.5, MacOS 11.6.8, and Ubuntu (just to be sure), with no errors across any of them: Update namespace, test on monterey · andrjohns/rstantools@9bf821d · GitHub

So it looks like there might be some strange quirk of your system/configuration that we need to chase down

EDIT: GHA workflow file here

Yeah, I also suspect there is something strange about my local setup. Could there be a global Makevars lurking somewhere else? Not sure I would know where to find it. I don’t have an ~/.R/Makevars.

My Mac workflows on GitHub Actions also run just fine.

In the main package I am working on, when I deleted configure and configure.win and added the src/Makevars you suggested, I get a different header error (below). Still an error, but progress.

> install.packages(".", type = "source", repos = NULL)
* installing *source* package ‘CENSORED’ ...
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c stanExports_CENSORED.cc -o stanExports_CENSORED.o
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/CholmodSupport:45:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching
      push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/KroneckerProduct:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop
      could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:39:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/Polynomials:135:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop
      could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:40:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop
      could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat.hpp:283:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/gaussian_dlm_obs_rng.hpp:138:7: warning: unused variable 'n' [-Wunused-variable]
  int n = G.rows();  // number of states
      ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:17:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/columns_dot_self.hpp:8:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/dot_self.hpp:38:41: warning: all paths through this function will call itself
      [-Winfinite-recursion]
  inline static double square(double x) { return square(x); }
                                        ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:70:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/functor/integrate_ode_adams.hpp:5:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/functor/cvodes_integrator.hpp:126:18: warning: unused variable 'coupled_size'
      [-Wunused-variable]
    const size_t coupled_size = cvodes_data.coupled_ode_.size();
                 ^
In file included from stanExports_CENSORED.cc:5:
In file included from ./stanExports_CENSORED.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:1238:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
    int ret = stan::services::error_codes::CONFIG;
        ^
In file included from stanExports_CENSORED.cc:5:
./stanExports_CENSORED.h:345:10: fatal error: 'stan_meta_header.hpp' file not found
#include <stan_meta_header.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~
22 warnings and 1 error generated.
make: *** [stanExports_CENSORED.o] Error 1
ERROR: compilation failed for package ‘CENSORED’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/CENSORED’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/CENSORED’
Warning message:
In install.packages(".", type = "source", repos = NULL) :
  installation of package ‘.’ had non-zero exit status

Ah yes sorry, forgot to add the include path for the current package (where the stan_meta_header.hpp file is). Try this one:

PKG_LIBS =  '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/' -ltbb
PKG_CPPFLAGS =   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include"  -I"../inst/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1
1 Like

Compilation and library(pkg) succeeded this time! How would you suggest I proceed with configuration?

Interesting! Can you post the full compilation output for the working installation? To see whether the makevars resulted in any other changes to the compilation arguments

Sure! The full output goes over the character limit, but here is most of it:

* installing to library ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library’
* installing *source* package ‘CENSORED_PKG’ ...
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include"  -I"../inst/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:

...

18 warnings generated.
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include"  -I"../inst/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c stanExports_CENSORED_MODEL.cc -o stanExports_CENSORED_MODEL.o
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:540:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:2:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/LU:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Jacobi:29:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:3:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Cholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:15:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Householder:27:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/QR:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:5:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SVD:48:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Geometry:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Eigenvalues:58:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:26:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCore:66:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/OrderingMethods:71:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:29:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseCholesky:43:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/SparseQR:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:14:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Sparse:33:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/IterativeLinearSolvers:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:32:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/CholmodSupport:45:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/KroneckerProduct:34:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:39:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/Polynomials:135:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/RcppEigenForward.h:40:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat.hpp:283:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/gaussian_dlm_obs_rng.hpp:138:7: warning: unused variable 'n' [-Wunused-variable]
  int n = G.rows();  // number of states
      ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:17:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/columns_dot_self.hpp:8:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/dot_self.hpp:38:41: warning: all paths through this function will call itself [-Winfinite-recursion]
  inline static double square(double x) { return square(x); }
                                        ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:70:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/functor/integrate_ode_adams.hpp:5:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/functor/cvodes_integrator.hpp:126:18: warning: unused variable 'coupled_size' [-Wunused-variable]
    const size_t coupled_size = cvodes_data.coupled_ode_.size();
                 ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:1238:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
    int ret = stan::services::error_codes::CONFIG;
        ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:46:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:13: warning: unused function 'set_zero_all_adjoints' [-Wunused-function]
static void set_zero_all_adjoints() {
            ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:6:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:47:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints_nested.hpp:17:13: warning: 'static' function 'set_zero_all_adjoints_nested' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
static void set_zero_all_adjoints_nested() {
            ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat.hpp:278:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_log.hpp:5:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_lpmf.hpp:60:9: warning: unused type alias 'T_partials_vec' [-Wunused-local-typedef]
  using T_partials_vec = typename Eigen::Matrix<T_partials_return, -1, 1>;
        ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat.hpp:328:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/poisson_log_glm_log.hpp:5:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/prob/poisson_log_glm_lpmf.hpp:52:9: warning: unused type alias 'T_alpha_val' [-Wunused-local-typedef]
  using T_alpha_val = typename std::conditional_t<
        ^
In file included from stanExports_CENSORED_MODEL.cc:5:
In file included from ./stanExports_CENSORED_MODEL.h:20:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/rstaninc.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include/rstan/stan_fit.hpp:35:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/test_gradients.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:51:
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/squared_distance.hpp:27:11: warning: unused type alias 'idx_t' [-Wunused-local-typedef]
    using idx_t = typename index_type<matrix_v>::type;
          ^
/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/squared_distance.hpp:64:11: warning: unused type alias 'idx_t' [-Wunused-local-typedef]
    using idx_t = typename index_type<matrix_d>::type;
          ^
In file included from stanExports_CENSORED_MODEL.cc:5:
./stanExports_CENSORED_MODEL.h:675:24: warning: unused typedef 'local_scalar_t__' [-Wunused-local-typedef]
        typedef double local_scalar_t__;
                       ^
29 warnings generated.
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o CENSORED_PKG.so RcppExports.o stanExports_CENSORED_MODEL.o /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/lib//libStanServices.a -L/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/lib/ -lStanHeaders -L/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/lib/ -ltbb -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/4.2/Resources/library/00LOCK-CENSORED_PKG/00new/CENSORED_PKG/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (CENSORED_PKG)

Thank you so much for your help, Andrew. I think we have made a lot of progress in finding a hard-coded fit-for-purpose Makevars that works for my system. Is there anything I can fix on my local machine to make the auto-generated Makevars from rstantools work?