Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug in R markdown file #153

Open
taooceros opened this issue Oct 23, 2021 · 5 comments
Open

Debug in R markdown file #153

taooceros opened this issue Oct 23, 2021 · 5 comments

Comments

@taooceros
Copy link

Is it possible to debug for a code chunk within a r markdown file? I think python jupyter notebook does support the feature, same as r studio.

@ManuelHentschel
Copy link
Owner

Unfortunately, this is not possible at the moment. Implementing this properly is going to be difficult (e.g. due to all the different settings/commands that can be specified for each code chunk).

To still allow some Rmd debugging, I can think of the following two alternatives:

  • Start a debug session with an empty workspace and send the code inside a chunk to the debug console (e.g. using ctrl+enter or the buttons provided by the vscode-R extension). To an extent this might already work.
  • Convert the entire Rmd file to R using e.g. knitr::purl() and debug that. This would ignore the .Rmd specific settings and division into chunks, but allow you to run the R code itself in the debugger. It might also be possible to implement this, so that the conversion is done automatically in the background.

@taooceros
Copy link
Author

taooceros commented Oct 29, 2021

Start a debug session with an empty workspace and send the code inside a chunk to the debug console (e.g. using ctrl+enter or the buttons provided by the vscode-R extension). To an extent this might already work.

That looks reasonable, and I remember the jupyter notebook do the same thing.
Convert the whole document to r will lose the advantage of rmd. Though I think the second option may be easier.

@markusgumbel
Copy link

I wonder if you could consider a chunk just a piece of code to be executed in the global environment. What variables are defined at debugging time is up to the user. He/she could run any chunks above (that would create those global variables) before debugging whenever needed.

Debugging a chunk is a very important feature in my opinion. Jetbrains' R plug in can do so - RStudio not.

But anyway, VS code's R features incl. this debugger are already excellent! Please go on!

@JZL
Copy link

JZL commented Nov 12, 2021

I agree and for what it's worth, where I find using the browser() debugger useful in rstudio .rmd files is to debug external libraries/other R files, stepping through the function calls to see where an error/bug is coming from. So I wouldn't need/want anything very crazy (or even cross rmd cell boundaries) -- just pulling out the current cell into an execution environment along with all the global/local vars.

If I made the plunge to use VScode over Rstudio I could definitely use purling to get it to work but I wanted to be careful about not losing the current environment.

@milanglacier
Copy link

milanglacier commented Jan 20, 2022

Start a debug session with an empty workspace and send the code inside a chunk to the debug console (e.g. using ctrl+enter or the buttons provided by the vscode-R extension). To an extent this might already work.

That looks reasonable, and I remember the jupyter notebook do the same thing. Convert the whole document to r will lose the advantage of rmd. Though I think the second option may be easier.

purl() exported .R file will have your code chunk separated by ## -----------------,

and you just simple replace ## ----------------- by # %%, and you can use the command palette run current chunk , which makes a R file runs blockwisely like rmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants