I’m creating an R package to fit certain statistical models using cmdstanr (GitHub - maxdrohde/exnexstan: R package to fit EXNEX models with Stan). However, the approach I’m using works when the package is installed on my computer, but not on others, so I don’t think I’m going about this correctly. Any suggestions are appreciated.
The approach I am using is as follows:
- Write the Stan code
- Compile it with
cmdstanr::cmdstan_model()
- Put the executable file generated in step 2 into the
inst
directory of the R package - When the package is installed, the files from the
inst
directory including the executable Stan models are put into the package directory of the user - Read in the the executable model file from the user’s package directory with
cmdstanr::cmdstan_model(exe_file = "executable_file)
wherefs::path_package()
is used to locate the executable Stan model
This process works when I install the package and run it on my own computer (where I compiled the Stan model originally). However, when I install the package on another computer, it doesn’t work because it seems to try reference files from the original computer. I’m not sure if this is an issue with how I compiled the code originally?
Example error:
Chain 1 dyld[46731]: Library not loaded: @rpath/libtbb.dylib
Chain 1 Referenced from: <82EF8E52-BC74-3AFF-8760-5C8A3D2EF828> /Library/Frameworks/R.framework/Versions/4.2/Resources/library/exnexstan/exnex
Chain 1 Reason: tried: '/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/max/.cmdstan/cmdstan-2.32.2/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/usr/local/lib/libtbb.dylib' (no such file), '/usr/lib/libtbb.dylib' (no such file, not in dyld cache)