Issues with individual CJS model in user manual

Hi
I am just learning stan in order to use it to run mark-recapture models. I have had difficulty running the individual CJS model in the stan manual, which fails for me when it gets to beginning of the functions block:

functions {
   int first_capture(int[] y_i) {
    for (k in 1:size(y_i))
      if (y_i[k])
        return k;
    return 0;

When I run the model it returns this error:

PARSER FAILED TO PARSE INPUT COMPLETELY
STOPPED AT LINE 10: 
functions {
   int first_capture(int[] y_i) {
    for (k in 1:size(y_i))
      if (y_i[k]) return k;
    return 0;............*prints the rest of the stan code*

Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'individual_CJS' due to the above error.
  }

I am running rstan, using R v. 4.0.3, and rstan v. 2.21.3. The data inputs for this model aren’t very clearly described, so I can’t tell if my inputs are wrong or something just isn’t working properly.

The collective CJS model on the same page works just fine with an input list like this:

history<-list(
  history=c(12,3,2,19,13,2,1),
  phi=c(.5,.5),
  p=c(.5, .5, .5))

As far as I can tell, the individual CJS model should be able to run with a list like the following, but it just doesn’t work:

history.array<-list(y=matrix(c(1,0,0,1,0,0,0,0,1,0,0,1,
         0,0,0,0,1,1,0,1,1,0,0,1,
         1,1,0,0,1,1,0,0,0,0,0,0,
         1,1,0,0,1,0,0,1), nrow=11),
T = as.integer(4),
I = as.integer(11),
phi = rep(.5,3),
p = rep(.5,4))

If anyone can tell me what is going sideways here, I’d really appreciate it.
thanks

Hard to tell with out more complete code.

Are you possibly missing a closing bracket?

No, the full code for the stan file is copied directly from the linked page of the manual. I learned this morning that the version of rstan on CRAN does not have up-to-date syntax. Unfortunately, direct installation of packages from the mc-stan repo isn’t working right now:

> install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
also installing the dependency ‘StanHeaders’

Warning in install.packages :
  unable to access index for repository https://mc-stan.org/r-packages/bin/macosx/big-sur-x86_64/contrib/4.3:
  cannot open URL 'https://mc-stan.org/r-packages/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES'

That’s just a warning that the binary package isn’t available and will instead try to install from source, does the installation succeed?

It gives this error and then automatically downloads rstan 2.21 from CRAN, which has the deprecated syntax. That installation succeeds, but is not compatible with current stan syntax.

EDIT here’s the rest of the error, which shows it pulling the older version from cran

> install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
also installing the dependency ‘StanHeaders’

Warning in install.packages :
  unable to access index for repository https://mc-stan.org/r-packages/bin/macosx/big-sur-x86_64/contrib/4.3:
  cannot open URL 'https://mc-stan.org/r-packages/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES'
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-x86_64/contrib/4.3/StanHeaders_2.21.0-7.tgz'
Content type 'application/x-gzip' length 1704598 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-x86_64/contrib/4.3/rstan_2.21.8.tgz'
Content type 'application/x-gzip' length 21020087 bytes (20.0 MB)
==================================================
downloaded 20.0 MB

cmdstanr will be more current.

thanks, I will give it a shot. It gave me the same error during installation, but defaulted to the source in the repo, rather than an old version in CRAN like rstan did.