RStudio won't run code in Quarto document

I run into an issue sporadically where RStudio won't run lines of code in a Quarto document. Cntrl-Enter does nothing. Rstudio's "Run" button does nothing. The green triangle to run a code chunk does nothing. But I can copy and paste the code into the console and it will run. I can still knit the entire document. Often the unresponsive code is just some chunks and not the whole document. Restarting R and/or RStudio usually doesn't help. This issue with non-responsiveness typically starts (and sometimes stops) while I'm editing the qmd file.
(Sorry, no reproducible example b/c I don't know how to recreate the issue. It happens when it happens.)

Maybe this is related to OneDrive?
My R project is stored in a OneDrive folder. I tried copying the .qmd file and associated data to a different computer, but when I tried to open the .qmd in RStudio, I get:

Error in load("...") : 
  bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘myfile.qmd’ has magic number '---'
  Use of save versions prior to 2 is deprecated 

But if I copy-and-paste all the code into a new .qmd file, it seems to work fine.

Maybe it's not OneDrive. When I move the project directory off OneDrive and copy-and-paste the code into a new qmd file, the problems persist.

Does what you are experiencing seem like the issues reported in this github issue?

No, that looks much worse. I can still move the cursor around normally. I can select code, copy-and-paste it to the console, and run it. I can knit the entire document. I just can't run the code from the source view.

An accompanying issue (that is at least correlated if not part of same issue) that I forgot to mention is that RStudio also often gets completely lost in the Outline view. It will skip headings and not list them, it will list a bunch of headings as subheadings of whatever is above them, even if they're not subheadings, etc. But again, this isn't an issue with the code itself. I have copied-and-pasted the full code to a new qmd file on another computer, and everything works normally there. The outline looks fine. I can run individual lines, code chunks, whatever.

One more tidbit: when RStudio started this behavior, it also quit indenting code at all. I often experience RStudio changing the number of spaces that it uses for indents on rmd and qmd files (from the 3 spaces specified in the settings to 2 spaces), but I haven't had it give up on indenting entirely before.

It seems that RStudio just kind of forgot how to understand the code so that it knows what's what.

What version of RStudio are you using? There were definitely some, um, exciting new issues along the lines of what you're describing in 2024.04.0. Some were fixed in 2024.04.2 (most recent release) but not all.

If you're game, you can also try the latest dailies of 2024.07 and see if that's better/worse, but still very much under active development (so buyer beware): https://dailies.rstudio.com/

1 Like

I'm using 2024.04.1 Build 748.
The computer that isn't having any issues with the code is running 2023.12.0 Build 369.

I have had similar problems and found that switching from the visual to the source view helped.

Thanks. That was helpful, handy. :+1:
Still broken, though: I have to highlight a line to execute just that line from cmd-return. If just cursor on a line, cmd-return tries to execute following lines.

This is a BUG in latest Posit/Quarto/R on Mac-Intel.