First and fourth questions are answered here - https://bookdown.org/yihui/rmarkdown/compile.html, although I would highly recommend to go through the relevant chapters of the book anyways. There is probably an answer to the third question somewhere in the book as well.
Second question is a little bit more tricky (especially with markdown), but in general you have whole family of functions to help you with this: browser, debugonce, recover. They are designed to help you at least narrow down the problem.
For example, I imagine, there is a particular function (or functions) that you'd want to debug, so you can add browser() into your markdown just before you are about to execute this function and you'll get exactly what you've described - state of R session at this point of time. You can then step through the calls and see what causes the error.