expose_stan_functions causes error: "$ operator is invalid for atomic vectors"
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
I'm working with experimental version 2.26 of RStan on Windows and I'm getting an error, "$ operator is invalid for atomic vectors", from expose_stan_functions.
I researched this a bit and did not find anything the same. Issue #899 mentions expose_stan_functions in passing but that appeared to be about other errors.
I get the error from an existing .stan file for which expose_stan_functions does not cause an error with RStan 2.26 on macOS. Instead of including the .stan file I'm working with, here is a shorter example which I nicked from another discussion. See: https://discourse.mc-stan.org/t/mixture-models/17721/9
functions {
real repulsive_lpdf(vector mu, vector rho) {
int K = num_elements(mu);
matrix[K, K] S = diag_matrix(rep_vector(1, K));
matrix[K, K] L;
int c = 0;
for (k1 in 1:(K - 1))
for (k2 in (k1 + 1):K){
c += 1;
S[k1, k2] = log(1 - exp(- squared_distance(mu[k1], mu[k2]) / rho[c]));
S[k2, k1] = S[k1, k2];
}
L = cholesky_decompose(S);
return 2 * sum(log(diagonal(L)));
}
}
data {
int<lower=1> K;
int<lower=1> N;
real y[N];
}
parameters {
ordered[K] mu;
vector<lower=0>[choose(K, 2)] rho;
real<lower=0> sigma[K];
simplex[K] lambda;
}
model {
// Prior model
mu ~ normal(0, 5);
sigma ~ std_normal();
lambda ~ dirichlet(rep_vector(3, K));
rho ~ gamma(1, 2);
mu ~ repulsive(rho);
// Observational model
for (n in 1:N) {
real comp_lpdf[K];
for (k in 1:K) {
comp_lpdf[k] = log(lambda[k]) + normal_lpdf(y[n] | mu[k], sigma[k]);
}
target += log_sum_exp(comp_lpdf);
}
}
I put that into a file name example.stan and then I get, in my R session:
> expose_stan_functions ("example.stan")
Error: $ operator is invalid for atomic vectors
packageVersion ("RStan") reports 2.26.2.
R.version.string reports "R version 4.1.0 (2021-05-18)".
Operating system is MS Windows 10.
I installed RStan following these instructions. (I was trying the officially released version 2.21, however, it lacks the %/% operator which I want to use.) See: https://discourse.mc-stan.org/t/problems-installing-rstan-2-21-2-with-rtools-4/22492/5
remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing expose_stan_functions("example.stan") with the supplied example.stan, RStan 2.26.2, R 4.1.0, and Windows 10 details. Trace the source of the "$ operator is invalid for atomic vectors" error and verify that the same call completes successfully without the error on the reported environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100