radian
radian copied to clipboard
Code excecution in radian terminal randomly stops
Hello there,
I have set up radian to run R code - and I did so successfully as R generally works in VSCode. However, fairly regularly some code snippets do not get executed when I hit 'control enter' or - when working with a RMarkdown document - I press the "Run Chunk" button. The code is sent to radian but then it appears to not get executed. The terminal doesn't even show the next line. Sometimes it helps to send the next command (or just even some random letter sequence plus hitting enter) and then the code gets executed. But sometimes even that doesn't help and I have to kill the terminal and start a new one. There is no error message of any sort.
It's not a code issue as it is never the same code snippet that causes this problem. The issue appears with any kind of code (e.g., loading data, plotting, basic data transformations). Also, when working on a RMarkdown document, I have no issues knitting it - even if I just encountered the problem described above with some code block contained therein.
Below are my relevant R settings in VSCode:
"r.sessionWatcher": true,
"r.rterm.windows": "C:\\\\Users\\\\XXXXX\\\\AppData\\\\Roaming\\\\Python\\\\Python37\\\\Scripts\\\\radian.exe",
"r.lsp.path": "C:\\Program Files\\R\\R-4.1.0\\bin\\R.exe",
"r.lsp.debug": false,
"r.rterm.option": [],
"r.plot.useHttpgd": true,
"r.session.viewers.viewColumn": {
"viewer": "Active",
"pageViewer": "Two",
"view": "Active"
},
"r.alwaysUseActiveTerminal": true,
"r.bracketedPaste": true
I searched far and wide for a solution but wasn't able to get to the bottom of this (or even solve it). Any help or pointers of how to fix is very much welcome.
I'm using:
- Windows 10
- VSCode 1.62.3
- R 4.1.0
- vscode-R 2.3.3
It is a known issue of the vscode-R on Windows. Search about "bracketed paste mode" on vscode-R. TLDR, the reason is that vscode terminal doesn't support bracketed paste mode.
Thanks for the response! I was aware of the "bracketed paste mode" issue - not fully aware that this is the reason for sluggishness of code execution. Set "r.alwaysUseActiveTerminal" and "r.bracketedPaste" both to false. Issue persists though.
I just recall that it could be an issue related to trailing newlines. radian uses trailing newlines to determine if a chunk should be evaluated. For example,
it doesn't include the trailing new line

and it does

This logic is important when a user copy and paste directly to radian console. For example, you could copy and paste a variable some_variable to radian directly and append + 1.

It is not possible without this trailing newline logic.
Another confusing bit is that, VSCode uses the settings bracketedPaste on Windows to control whether the text should be sent at once to radian or be sent line by line. It is technically not bracketed paste mode, but neither totally unrelated, though. VScode in Windows doesn't support bracketed paste mode, but thanks to prompt toolkit, we are able to behave like bracketed paste mode when a chunk of text is sent to radian at once. You should always turn on the setting bracketedPaste on Windows to allow the code to be sent at once.
Thanks for this (and apologies for the slow response - things are extremely busy at work at the moment).
bracketedPaste is actually turned on - I just forgot that I already changed this setting again.
Based on your post (and the other thread you refer too as well as some of the threads mentioned therein), I explored this issue a bit more and noticed the following:
- It is primarily longer code blocks that don't run (e.g., elaborate
ggplotcommands) or things like loading datasets and shapefiles. - When I hit Ctrl + Enter to send code to the terminal, I can actually still edit the code.
- When I copy and paste code directly into radian, there seems to be no problem. Everything works fine and I can run code that normally causes the problem over and over again.
- I also noticed that there is an additional bracket added to the code when it doesn't execute. I didn't realize this before.
Not quite sure though whether I understand the trailing new line logic you mentioned... My code currently doesn't include any trailing whitespace or new lines. I'm quite particular about this and always avoid those. Do you propose to include a trailing new line in order to execute the code properly? If that's what you meant: I tried it and it didn't resolve the problem.
But based on above observations and some threads mentioned here , I found another solution. I created a radian profile where I set options(radian.auto_match = FALSE). Code execution works much better now. Every now and then, it still doesn't get executed but then simply pressing Enter in radian resolves this too. So, overall, the situation has improved.
I am experiencing the same problem.
I think I'm getting a partial presentation of this. Starting in the last month or two whenever I try to execute code, or even just paste it into the console, there's a fairly high chance that radian will completely lock up for a good 10+ seconds before continuing.
Neither RAM nor CPU get maxed out, it happens even with very short single-line blocks of code, there doesn't seem to be any correlation between how costly the code is to execute or length of the command in the console, and it persists even after fully uninstalling and reinstalling both python and radian.
I was having thie same issue and this fixed it.
- create a file named
.radian_profilein root of the working directory - in it, paste
options(radian.auto_match = FALSE)
i found this tip here: https://stackoverflow.com/questions/71410887/vscode-radian-does-not-run-the-code-sometimes
Edit: Also anecdotally i've found that an RMarkdown code chunk that ends with just a closing paren seems to help this issue
Bad:
mt_cars %>%
select(mpg)
Good:
mt_cars %>%
select(
mpg
)