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

Unexpected Closing Parentheses and Braces When Executing Code Chunks in R

Open brianmsm opened this issue 2 years ago • 9 comments

Describe the bug When executing certain chunks of R code using VSCode with the R extension and Radian, I sometimes observe additional closing parentheses or braces being sent to the console, which were not present in the original code. This issue seems to occur after a small delay.

To Reproduce This issue occurs sporadically and I have been unable to identify a consistent pattern. However, I've noticed that it happens frequently when I run the following chunks of R code multiple times:

data_test <- reduce(rep(list(mtcars), 2), bind_rows)

Can you fix this issue by yourself? (We appreciate the help)

No

(If applicable) Please attach setting.json

{
    "[r]": {
        "editor.defaultFormatter": "REditorSupport.r",
        "editor.formatOnSave": false,
        "editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?"
    },
    "[rmd]": {
        "editor.defaultFormatter": "REditorSupport.r",
        "editor.formatOnSave": false
    },
    "r.rmarkdown.knit.openOutputFile": true,
    "r.rmarkdown.codeLensCommands": [
        "r.runCurrentChunk",
        "r.runAboveChunks",
        "r.runBelowChunks"
    ],
    "r.source.encoding": "UTF-8",
    "r.source.focus": "editor",
    "r.alwaysUseActiveTerminal": false,
    "r.sessionWatcher": true,
    "r.rtermSendDelay": 8,
    "r.plot.useHttpgd": true,
    "r.lsp.debug": true,
    "r.rterm.windows": "C:\\Users\\brian\\AppData\\Local\\Programs\\Python\\Python311\\Scripts\\radian.exe",
    "r.liveShare.defaults.commandForward": true,
    "r.rterm.linux": "/usr/bin/radian",
    "r.liveShare.defaults.shareBrowser": true,
    "r.bracketedPaste": true,
    "r.session.levelOfObjectDetail": "Normal"
}

Expected behavior I expect the code to be sent to the console as it is, without any additional characters.

Screenshots Animation

Environment (please complete the following information):

  • OS: Windows 11
  • R Version: 4.3.0
  • VSCode Version: 1.79.2
  • Radian Version: 0.6.4

Additional context I noticed that when I format the code differently, the problem does not occur. For instance, the following code does not produce the issue:

data_test <- reduce(
  rep(list(mtcars), 2),
  bind_rows
)

In addition, it also does not play when instead of using bind_rows, I use rbind :

data_test <- reduce(rep(list(mtcars), 2), rbind)

brianmsm avatar Jul 02 '23 23:07 brianmsm

I have been aware of this issue for the past two years and have been searching for a solution, as having this problem renders Radian completely unusable. However, I have been unable to find a solution thus far.

Based on the results of my attempts, I have found that this problem is prone to occur when executing lines of code that contain numerous parentheses(for reference only).

I made an example, a formula I scribbled. When I run it slowly, there are no errors. However, when I run it continuously, unexpected brackets appear.

https://github.com/REditorSupport/vscode-R/assets/107530058/db324ae5-b8f0-4362-a568-d5809ec227de

When I run a shortened version of the formula, even with a quick click, it runs without errors.

https://github.com/REditorSupport/vscode-R/assets/107530058/5237858c-8708-4852-b0e6-691fc94c7398

Similar error donot occur in R terminal (not radian).

https://github.com/REditorSupport/vscode-R/assets/107530058/b6796ffe-1e8e-4eee-92bc-358df9d41e44

LR1933 avatar Jul 07 '23 05:07 LR1933

Well, this seems to be an old and already known problem: https://github.com/REditorSupport/vscode-R/issues/419, https://github.com/REditorSupport/vscode-R/issues/820, https://github.com/randy3k/radian/issues/303, https://github.com/randy3k/radian/issues/277, https://github.com/randy3k/radian/issues/230 . And it is only happening on windows, because Bracketed paste mode is not supported.

The first one associated with the addition of parentheses or braces when sending a code to the console. It seems as if there is a brief desynchronization when sending the code to the console, and radian tries to close parenthesis before seeing that it was already closed. This can be easily fixed by disabling auto-completion in the .Rprofile or .radian_profile file.

options(radian.auto_match = FALSE)
  1. The second is a bit more problematic and is apparently occurring when the code block is very large, or when a chunk is executed that has several code blocks and these have to be sent all at once to the console. There is a very temporary workaround proposed here that reduces the number of times the problem occurs, although it still happens: https://github.com/REditorSupport/vscode-R/issues/820#issuecomment-1002937100

brianmsm avatar Jul 16 '23 04:07 brianmsm

I remembered that someone told me this before, but I don't know where ".radian_profile" is. Can you tell me how to find ".radian_profile", thanks.

LR1933 avatar Jul 19 '23 00:07 LR1933

@brianmsm There's also, in my experience at least, two new showstopping bugs that started recently: Radian eventually stops printing any output at all, and prior to that it will begin freezing for tens of seconds or more at a time in the middle of executing even a single line of code.

What's interesting to me is all of these feel like regressions. When I first began using VSCode-R with Radian the only issue I had consistently was the buildup of background processes from the language server, and only something as huge as an entire shiny app would fail to auto-execute on ctrl+enter. Both VSCode-R and Radian have steadily gotten less reliable and performant with time.

For example starting an R session with the built in command palette function on an SSH remote is unusable, but calling R at the terminal to create an R session works great.

D3SL avatar Jul 20 '23 06:07 D3SL

There's also, in my experience at least, two new showstopping bugs that started recently: Radian eventually stops printing any output at all, and prior to that it will begin freezing for tens of seconds or more at a time in the middle of executing even a single line of code.

@D3SL Can you reproduce this on my reference deployment at https://demo.jupyter.b-data.ch?

  • OS: Debian 12
  • Code Version: 1.79.2
  • Radian Version: 0.6.6
    • r executable: /usr/local/lib/R/bin/R
    • r version: 4.3.1
    • python executable: /usr/local/bin/python
    • python version: 3.11.4

ℹ️ These seem to be Windows specific issues.

benz0li avatar Jul 21 '23 09:07 benz0li

New to VSCode-R, and love the idea of it more than the experience at this point. These bugs - persisting even after trying solutions - make Radian completely unusable. Hard to believe these problems have persisted for years apparently.

nicholskl avatar Jul 28 '23 17:07 nicholskl

I am still having this issue using Windows 10. Radian is not usable in its current state for me.

thedbcooper avatar Feb 20 '24 17:02 thedbcooper

Unbelievable that this hasn't been fixed or addressed.

nicholskl avatar Feb 21 '24 16:02 nicholskl

@nicholskl that's a bit over the line. First this is fundamentally a problem with Windows itself, and second VSCode-R is basically a two-man show run by Renkun-ken and Ikuyadeu. And they're fighting an uphill battle against the RStudio monopoly.

D3SL avatar Feb 21 '24 17:02 D3SL