How to debug a rmarkdown file

Hello all,
I am building html documents using rmarkdown.
I render those documents by running rmarkdown::render(input, output_file, params), I have the following problem when I want to debug. I can set manually a browser() breakpoint in the Rmd document and it stops fine. However I need to run sink() each time to get command line to "print" instructions anymore.
I'd like to use options(error=recover) but because on the above mentioned problem I cannot even select the frame I want to recover to.

Is there a way to avoid having to do sink() all the time ?
Is there an advised way of debuging rmarkdown documents ?
I am not using Rstudio (I work in vim with the nvim-R plugin)

Regards

I wanted to advice using the code execution chunk by chunk, but it is an RStudio feature!
Very useful to debug or just check step by step that everythink is working before render all.

An idea : extract the R code from an rmarkdown using knitr::purl. That will give you an Rscript that could be easier to debug.

2 Likes