I have recently updated rstan (version 2.26.4) and R (version 4.1.2). Running expose_stan_functions now throws the following error:
“Error: $ operator is invalid for atomic vectors”
An example:
model_code <-
'
functions {
real standard_normal_rng() {
return normal_rng(0,1);
}
}
'
expose_stan_functions(stanc(model_code = model_code))
# Error: $ operator is invalid for atomic vectors
The error comes from the underlying call to rstan::expose_stan_functions which brms::expose_functions is a wrapper for. It can be caused by a few things, but the main culprits are usually a version of withr > 2.2.0 or an out of date installation of RcppParallel.
Many thanks for the reply. Unfortunately the error persists even after installing withr version 2.2.0 followed by updating RcppParallel and reinstalling rstan and StanHeaders
Same error is present, but I believe it’s separate from the TBB. I stepped through the expose_stan_functions source and it turns out that the Rcpp::sourceCpp call was returning an error:
In file included from C:/Users/Andrew Johnson/Documents/R/win-library/4.1/StanHeaders/include/src/stan/model/model_header.hpp:7,
from file3bfc5caa636.cpp:14:
C:/Users/Andrew Johnson/Documents/R/win-library/4.1/StanHeaders/include/src/stan/io/dump.hpp: In member function 'virtual void stan::io::dump::validate_dims(const string&, const string&, const string&, const std::vector<long long unsigned int>&) const':
C:/Users/Andrew Johnson/Documents/R/win-library/4.1/StanHeaders/include/src/stan/io/dump.hpp:778:15: error: 'validate_dims' is not a member of 'stan::io'
stan::io::validate_dims(*this, stage, name, base_type, dims_declared);
^~~~~~~~~~~~~
C:/Users/Andrew Johnson/Documents/R/win-library/4.1/StanHeaders/include/src/stan/io/dump.hpp:778:15: note: suggested alternative: 'validate_zero_buf'
stan::io::validate_dims(*this, stage, name, base_type, dims_declared);
^~~~~~~~~~~~~
validate_zero_buf
Even though USE_STANC3 was defined. Because the call is wrapped in a try statement in expose_stan_functions it was failing silently. It looks like the generated c++ just needed to have the rstan includes added like with the main stan_model calls:
This looks like a USE_STANC3 issue where the headers are incompatible (v2.21 vs v2.26). I have no problem running expose_stan_functions() on my system. The error message can be improved, but any failed compilation will lead to this error right now.
I am getting the same error on Mac OS 12.0.1. I have removed/reinstalled RStan according to the above instructions, but to no avail. Has there been a solution for this issue?
> version
_
platform aarch64-apple-darwin20
arch aarch64
os darwin20
system aarch64, darwin20
status
major 4
minor 1.2
year 2021
month 11
day 01
svn rev 81115
language R
version.string R version 4.1.2 (2021-11-01)
nickname Bird Hippie
I tried installing the experimental version but could only install the StanHeaders. Installation of rstan fails with the following error:
Warning in i.p(...) :
installation of package ‘C:/Users/Sandhu/AppData/Local/Temp/RtmpaKrc6K/file304c4e66448d/rstan_2.28.2.9000.tar.gz’ had non-zero exit status
Install the binary packages for Windows from the latest artifacts (currently, at https://github.com/stan-dev/rstan/actions/runs/1647298750): assuming that you’re on R-release, scroll down to the packages, download R-release_windows-latest.zip, and unzip it. Then, install the packages (from your current working directory) using:
I have successfully installed StanHeaders and rstan (v 2.28.2.9000) and can confirm that expose_stan_functions now works fine. I have tested it using the following example.
I just ran into this same issue again under rstan and StanHeaders 2.28.2.9000 and I couldn’t for the life of me figure out what was causing it but apparently it can occur as a result of spaces in the parent folder. Changing the directory from E:\Users\Dropbox\Projects\The Threat from Within\renv\library\R-4.1\x86_64-w64-mingw32\StanHeaders to E:\Users\Dropbox\Projects\The-Threat-from-Within\renv\library\R-4.1\x86_64-w64-mingw32\StanHeaders solved the issue and everything works perfectly now.
If it isn’t already in there somewhere that when using renv for version control, spaces in the file path can cause a ton of issues with rstan and StanHeaders it may be worth adding that to the docs/wiki? @andrjohns@hsbadr