The amount of memory used you always can find in the memory report in the RStudio IDE (top right part of the IDE in the Environment/History/... part.
Unless you set any limitations on the system side or add limits into local launcher or even use SLURM launcher, RStudio will consume all the memory it can get before running out of it and then the so-called OOM will kill the process that consumes the most of memory - this is when RStudio will close according to my theory.
As a next step, can you please open a terminal in the RStudio IDE (Alternatively log into your ubuntu 22.04 server via ssh), type the following commands
curl -O https://mc-stan.org/r-packages/src/contrib/rstan_2.26.22.tar.gz
R CMD INSTALL rstan_2.26.22.tar.gz
and send the output ? (If the second command complains about "R not found" you may need to specify the full path to the R
binary (e.g. /opt/R/4.2.3/bin/R
)