ODE in RStudio, incorrect "variable does not exist" diagnostic error message

Hello, I am using cmdstan “2.28.1”, R version 4.1.1 and Rstudio 2021.09.0 Build 351 on Windows 64. In coding up a predator-prey model (with a custom user function called “dy_dt”) and using the new ODE functions (ode_rk45), I noticed that the Rstudio diagnostics flagged an error at the line where ode_rk45 was called, with error message “variable ‘dy_dt’ does not exist”. However, there was actually no error in any of the code, and the model compiled and fit perfectly (thanks STAN!). But I was curious if it was something particular about my code that caused the diagnostic error to show, so I downloaded the sample code for the simple SIR model (example-models/sir.stan at master · stan-dev/example-models · GitHub) which was provided as a demonstration of the new ODE function formats. And sure enough, the same diagnostic error comes up when that sample code is opened in Rstudio, on line 44, error message “variable simple_SIR does not exist”, although again there is clearly no actual error and the code compiles and runs just fine. So it seems that Rstudio diagnostics do not recognize the new ODE function call formats and flag them as errors. This is not a critical problem as the code still compiles and fits perfectly (with cmdstan), but it is an inconvenience as it essentially renders the diagnostics useless, since any other real errors lower down in the code will not get flagged. Maybe this is an Rstudio problem?

1 Like

The Rstudio code highlighting uses rstan and since the rstan version has older Stan that doesn’t have the new ODE interface yet, it gives that message

1 Like

Thanks, that makes sense - sorry for the false alarm!

1 Like