Rstan: any init_r counterpart for optimizing to deal with initialization failure?

I didn’t try it myself, but I think cmdstanr should let you use custom C++ code, see e.g. this thread: Custom c++ using cmdstanr? - #9 by rok_cesnovar that shows how to do it - although it is a bit less user friendly than in rstan.