RStan transformed data puzzle on Mac

Hi, this seems to be a very strange problem.
I have this transformed data block

transformed data {
int k = 4; //number of parameters
int m = 5; //number of parameters for NN50

On my Mac at home this and the program in which it is embedded compiles and works without problem.
When I try to run the same program on the Mac at work I get


ERROR at line 18

17: transformed data {
18: int k = 4; //number of parameters
19: int m = 5; //number of parameters for NN50


I’m really puzzled by this. I’ve tried declaring
int k;
int m;
k = 4;
m = 5;

but then it also gives an error.


There is a typo somewhere. What is the full Stan program that does not parse?

Hi, thanks - I thought it was unnecessary to include the whole program, since it does actually work on another computer. But here it is …

data {
int<lower=0> n;
vector[n] group;
vector[n] woman;
vector[n] control;
int<lower=0,upper=20> nshocks[n];

transformed data {
int k = 4; //number of parameters
int m = 5; //number of parameters for NN50

parameters {
vector<lower=0,upper=1>[n] theta;
simplex[k] b_raw;
real<lower=0> b_scale;
ordered[2] mu;
real<lower=0> vtheta;

transformed parameters {
vector[k] b_nshocks;
b_nshocks = b_scale*(b_raw - 1.0/k);

model {
real mutheta;
real munn50;
vector[k] alpha;

    for (i in 1:k) {
        alpha[i] = 1;
    b_raw ~ dirichlet(alpha);
    b_scale ~ normal(0,5) T[0,];
    for (i in 1:2) {
        mu[i] ~ normal(10,10) T[0,20];

    vtheta ~ cauchy(0,1);

    for(i in 1:n) {
            mutheta = inv_logit(b_nshocks[1] + b_nshocks[2]*control[i] + b_nshocks[3]*group[i] + b_nshocks[4]*woman[i]);
            theta[i] ~ beta(mutheta*vtheta,(1-mutheta)*vtheta);

            target += log_mix(theta[i],poisson_lpmf(nshocks[i]|mu[1]),poisson_lpmf(nshocks[i]|mu[2]));


That is legal syntax. My guess is that on the computer where it does not parse, there is a different language or encoding setting. In RStudio there is a setting for this under Global Options -> Code -> Saving.

Hi, thanks for this suggestion. I’ve checked the settings between the home Mac and the work Mac, but there are no differences. I tried various settings, also checked that I had all libraries up to date, but nothing seems to solve this very strange problem.

hi, I solved the problem by reinstalling everything, R, RStudio and Rstan on the work computer, now it all works fine.
(Still is a strange error, and cause unknown).