Code running much slower on Rmarkdown than R script after update

I recently updated to the latest versions of R and R Studio on my new M1 Max machine. After the update, however, Rmarkdown runs very slow compared to a regular R script, when I have largish amounts of data loaded to memory.

This is with any code I run. For example, the following code takes 0.02736592 secs on Rscript and 2.401871 secs on Rmarkdown.


start_time <- Sys.time()

mpg %>% 
  mutate(age = if_else(year > 2000, "New", "Old")) %>% 
  group_by(age) %>% 
  summarize(cyl = mean(cyl, na.rm = TRUE))

Sys.time() - start_time

I have tried uninstalling and reinstalling markdown and Rmarkdown packages, and even R, Rstudio, and Anaconda but nothing is working.

Note: This happens when I have lots of data loaded in R. For this example, I had ~3GB of data loaded in R. When there is no data loaded to memory, performance is similar.

I originally posted this question on stack overflow, but didn't get any response. This is the link to the original posting: performance - Rmarkdown runs much more slowly than R script after update - Stack Overflow

I can't they for sure where this is coming from.

an idea to identify:

Did you test inside and outside RStudio for the rendering ? using knit button, and rmarkdown::render() directly ?

I tried this. rmarkdown::render() is slightly faster to knit.

Also, as a side note, when I run code in rmarkdown, regardless of the complexity of the code line, it takes a while to run that line. It almost feels like the system is adding pauses between lines.

I reinstalled the previous version of RStudio I was using (2022.07.2) and it seems to have solved the issue. It must be an issue with the recent release of Rstudio.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.