Intermittent failure of RStudio "Check on Save"

I am using rstan 2.19.3 and RStudio Version 1.1.453.
When I save the following stan code:

functions {  
real anorm(real theta,
            real mean,
            real sq){
 return   (1 + expm1(-(1/(2 * sq)) * (theta - mean)^2));   
}
}

with “Check on Save” ticked I get this in the Console:

R>rstan:::rstudio_stanc(“mre.stan”)
mre.stan is syntactically correct.
which is as it should be.
But if I add another term to the function definition in my stan code, thus:

functions {  
real anorm(real theta,
            real mean,
            real sq){
 return    sqrt(1/ (2 * pi * sq)) * (1 + expm1(-(1/(2 * sq)) * (theta - mean)^2));   
}
}

and then save with “Check onSave” ticked, as before, I get this in the Console:

R>rstan:::rstudio_stanc(“mre1.stan”)
R>
which is no good.

I thought at first that I had the problem described here https://discourse.mc-stan.org/t/syntax-errors-not-showing-on-save-even-though-check-on-save-is-checked/12298

and I have reloaded rstan as suggested there, but my problem is quite different because Check on Save does work sometimes.

Help, please!

I had something similar. There was a special way to reinstall it that helped - I think it was called Install from source.

Catalina?

I should have said. Yes I am running ` Macbook pro with Catalina 10.15.3.
If this is a Catalina problem is it solvable or do I have find a Mac without Catalina installed?

You probably just need to do

install.packages(c("StanHeaders", "rstan"), type = "source")

Hello Ben,
I have just tried that but it does not solve the problem: exactly the same as before.

When you do

library(rstan)
stanc("mre.stan")

what happens when mre.stan has a typo?

If I omit the semicolon at the end of a line, like so:

functions {  
real anorm(real theta,
            real mean,
            real sq){
 return   (1 + expm1(-(1/(2 * sq)) * (theta - mean)^2))
}
}

and do

library(rstan)
stanc(“mre.stan”)

I get this:

R>library(rstan)
R>stanc(“mre.stan”)
R>rstan:::rstudio_stanc(“mre.stan”)
R>

which is not right.

I am pretty sure that if you have the C++ toolchain installed correctly like in

then if you install rstan from source, the exceptions thrown by the parser in the event of an invalid Stan program should be handled appropriately, rather than what you are seeing.

Thanks, Ben. All is working now.