vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Radian "works" but won't run my code properly

Open BertrandToulas opened this issue 3 years ago • 6 comments
trafficstars

When I try to run my code in VS Code via the run button OR ctrl + shift + enter, the radian terminal gives me the following message:

source("c:\\Users\\username\\myfilepath\\...\\file.r", encoding = "UTF-8")
")

If I try several times in a row, it prints out the same thing, but adds more closing parentheses at the end.

On the other hand, if I try to run my code via ctrl + enter (without shift), radian runs only the last line of the code. It doesn't read or recognize anything prior to the last line of my file. For example, I will get an "object not found" error if I create an object on the first line and try to print it on the second. Only if I first highlight all the code and then press ctrl + enter will it print ou the entire selection and the proper result in the radan console.

Here are my JSON settings:

"r.bracketedPaste": true,  
"r.alwaysUseActiveTerminal": true,
"r.rterm.windows": "C:\\Users\\berut\\pyver\\py395\\Scripts\\radian.exe",
"r.plot.useHttpgd": true,
"r.rpath.windows": "C:\\Program Files\\R\\R-4.2.0\\bin\\R.exe",
"r.rterm.option": []

At a complete loss what I'm doing wrong, even after scouring reddit and stackoverflow and youtube...

I'm using the latest versions of VSCode, R, the R extension and R Debugger extension on Windows 11 (not WSL).

BertrandToulas avatar Apr 30 '22 12:04 BertrandToulas

In case you're interested in a temporary solution, you should know that you should be able to delete the ") at the end. Doing so and pressing enter will send the rest of the command to the terminal.

If this happens everytime it will get annoying, though, so you have have found you prefer Ctrl + A, Ctrl + Enter, though the output is difficult to read with all the intertwined code in the terminal.

Also, Ctrl + Enter and Ctrl + Shift + Enter do very different things. The latter executes the whole active document file (by sending a source(...) call inside R, while the former just sends the current line of text to the terminal.

Does this bug appear very often for you, or can you reliably reproduce it? I have previously encountered the behaviour but I can't reproduce it so never bothered to raise an issue.

LucasFA avatar May 25 '22 21:05 LucasFA

I am also having this issue. I cannot reproduce it reliably, but it breaks my work flow to the point that VS Code is barely use-able.

natereal avatar Jul 04 '22 00:07 natereal

There's a partial fix here in #820. It solves the duplicated brackets/quotes/parens issue but it doesn't solve the problem of code not actually being run when you use ctrl+enter, at least for me. It's still a substantial QOL improvement though to not have typos forced into the code constantly.

D3SL avatar Oct 09 '22 06:10 D3SL

I have this typo constantly. I assumed it was just related to UNC paths on my Windows machine. But good to know others experience it too. It drives me crazy and is a big factor why I use RStudio more than VS Code for my R development.

bschneidr avatar Jun 16 '23 01:06 bschneidr

See also issue https://github.com/REditorSupport/vscode-R/issues/1390.

benz0li avatar Jul 10 '23 15:07 benz0li