Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging code in R Markdown

Tags:

I've been playing a little bit with R Markdown and I really like it, because after each of my analyses I need to write a (Word) report detailing the results. With R Markdown, the code and report are the same document, so it's easy to remember that I chose to perform analysis B at a certain point in the code, because of the results of analysis A before.

However, I'm not able to set breakpoints in R Markdown inside R Studio, and this limits severely the possibility of performing efficient debugging. This implies that in the end I can only use Markdown for very trivial analyses, where the R code is so simple that either I don't have to debug it, or I can debug it manually. It this to be expected, i.e., is it well-known that R Markdown can only be used for simple analyses? Or is there a solution?

like image 966
DeltaIV Avatar asked Mar 15 '17 16:03

DeltaIV


1 Answers

You can use browser() in your code to set breakpoints. See https://support.rstudio.com/hc/en-us/articles/205612627-Debugging-with-RStudio#debugging-in-r-markdown-documents

I've find it more useful to write custom functions in a .R and source() it in Markdown. Then, you get the best of both worlds.

like image 97
Victor Kostyuk Avatar answered Oct 30 '22 13:10

Victor Kostyuk