Number of spaces in tab in RMD and QMD documents

Rstudio frequently switches to using 2 spaces for tabs instead of the 3 that I have set in the options (for both global and project). It particularly likes to use 2 spaces for RMD and QMD documents, but it doesn't always use 2 spaces. Some days it uses 3. I haven't figured out exactly when it will use 2 or 3, but typically it starts out using 3 on new documents, then switches to using 2. How do I force it to use the number of spaces that I've chosen in the settings?

I'm using version 2024.04.1 Build 748, but I've been frustrated by this behavior through several versions of Rstudio.

Interestingly, RStudio only switches to using 2 spaces on certain documents. I can open a new QMD document and it will use 3 spaces on the new document.

The switch from 3 to 2 spaces only seems to occur when I close and later re-open RStudio.