Semantic error when use stan_model()

I’m using stan_model as below to define a model written in a load_model() function.

mod_dm <- stan_model(model_code = csSampling::load_model())

But I get the error below

Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  0

Semantic error in 'string', line 10, column 8 to column 14:

Too many indexes, expression dimensions=1, indexes found=2.

The model I’m trying to define is

load_model <- function(){
 model0 <- paste0("functions{

real wt_multinomial_lpmf(int[,] y, vector lambda, vector weights, int n, int K){
    vector[K] theta;
    real check_term;
	int tmpy[K];
    theta = lambda / sum(lambda);
    check_term  = 0.0;
    for( i in 1:n )
    {
	tmpy = y[i,:];
	check_term    = check_term + weights[i] *  multinomial_lpmf(tmpy | theta);
    }
    return check_term;
  }
} /* end function{} block */

data {
	int<lower=1> n;
	int<lower=0> K;
	int<lower=0, upper = 1> y[n,K];
	vector<lower=0>[n] weights;
	vector<lower=0>[K] alpha;
}

parameters {
  vector<lower=0>[K] lambda;
}
transformed parameters{
  simplex[K] theta = lambda / sum(lambda);
  vector[K] loglam = log(lambda);
}

model {
	//theta ~ dirichlet(alpha);
	lambda    ~ gamma(alpha, 1 );
	target += wt_multinomial_lpmf(y | lambda, weights, n, K);
}"
  )
 return(model0)
}

The same code work well on a colleague’s machine but not on mine.

I’m using R 4.2.1 and rstan 2.26.13. following the instructions here