vscode-R
vscode-R copied to clipboard
Send code to terminal by `Ctrl + ENTER` but don't run
Describe the bug
When I send code to terminal by Ctrl + ENTER, it just send code but don't run code, and we should move focus to terminal and input ENTER manually to run the code.
To Reproduce Steps to reproduce the behavior:
- create a terminal
- run this code below:
library(IlluminaHumanMethylation450kanno.ilmn12.hg19)
## sorry for this, I have tried other code which don't rely on any package data to reproduce this problem but it failed.
## this package is from bioconductor
## so we should install it by BiocManager::install("IlluminaHumanMethylation450kanno.ilmn12.hg19")
library(tidyverse)
After loading packages, try this code below several times, the frequency of problem is almost 1/2, so it won't be hard to reproduce this problems
probe_with_one_more_gene <- Other$UCSC_RefGene_Name %>%
purrr::map(~ unique(str_split(., pattern = ";")[[1]])) %>%
purrr::map_lgl(
~ length(.) >= 2
) %>%
{ # nolint
rownames(Other)[.]
}
- See error (it seems vscode-r just run code before line
rownames(Other)[.]and after code wasn't run, as we could see a character+after the linerownames(Other)[.]which indicates the line before should have been run.)
if we don't run it manully, we can even delete code like this.

The problems only occured in radian terminal no matter I turn on or off r.bracketedPaste setting. the code run by raw r terminal is like this which looks like raw r terminal run code line by line as indicated by the character +.

Do you want to fix by self? (We hope your help!)
Yes, I want to be helpful.
(If yes,) what kind of help do you want? (e.g. Which file should I fix, Survey (related documents)
(If related)setting.json
"[r]": {
"editor.rulers": [
80
],
"editor.wordWrap": "bounded",
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?",
"rewrap.autoWrap.enabled": true,
"rewrap.wrappingColumn": 80,
"rewrap.doubleSentenceSpacing": true
},
"r.alwaysUseActiveTerminal": true,
// "r.bracketedPaste": true,
"r.rpath.windows": "C:\\Yun\\R\\R-4.1.1\\bin\\x64\\R.exe",
"r.rterm.windows": "C:\\Users\\****\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\radian.exe",
// "r.rterm.windows": "C:\\Yun\\R\\R-4.1.1\\bin\\x64\\Rterm.exe",
"r.rterm.option": [
"--no-save",
"--no-restore",
"--local-history",
"--r-binary=C:\\Yun\\R\\R-4.1.1\\bin\\x64\\R.exe"
],
"r.plot.useHttpgd": true,
"r.session.levelOfObjectDetail": "Detailed",
"r.session.objectLengthLimit": 100,
"r.session.viewers.viewColumn": {
"plot": "Active",
"viewer": "Active",
"view": "Active",
"helpPanel": "Active"
}
Expected behavior
Run code directly when sending code by typing Ctrl + ENTER
Environment (please complete the following information):
- OS: Windows 19042.1237
- VSCode Version: 1.61.0
- R Version: 4.1.1
- vscode-R version: v2.3.1
Additional context
If we could run code line by line like raw r terminal when sending code?
I tried sending your code to R without bracket paste mode and sending it to radian with bracket paste mode. Both work as expected.
Thanks for your quickly reply, I came across it one time in every two times run of this code:
probe_with_one_more_gene <- Other$UCSC_RefGene_Name %>%
purrr::map(~ unique(str_split(., pattern = ";")[[1]])) %>%
purrr::map_lgl(
~ length(.) >= 2
) %>%
{ # nolint
rownames(Other)[.]
}
I don't know what's the matter, it agains

Do you select the code and send it or put the cursor in the beginning of the code and send it?
I just put the cursor in the beginning of the code sometimes in the median of the first line of the code block and type Ctrl + ENTER
What if you remove # nolint and try again?
Thanks for your help, it remains here

and I can delete code after character +.

I move the curly braces to the last line or remove it, it remains here:


Looks like it is a Windows-specific issue where ~~radian~~ vscode terminal does not support bracket paste mode (is it still true today?). It does not occur on macOS and Linux.
@randy3k Maybe it is because radian does not handle such expressions well on Windows?
What if you select the code and send it?
It remains here and I can delete code after character +



here is my .radian_profile:
# Do not copy the whole configuration, just specify what you need!
# see https://help.farbox.com/pygments.html
# for a list of supported color schemes, default scheme is "native"
options(radian.color_scheme = "monokai")
# either `"emacs"` (default) or `"vi"`.
# options(radian.editing_mode = "emacs")
# indent continuation lines
# turn this off if you want to copy code without the extra indentation;
# but it leads to less elegent layout
options(radian.indent_lines = FALSE)
# auto match brackets and quotes
options(radian.auto_match = FALSE)
# highlight matching bracket
options(radian.highlight_matching_bracket = FALSE)
# auto indentation for new line and curly braces
options(radian.auto_indentation = TRUE)
options(radian.tab_size = 4)
# pop up completion while typing
options(radian.complete_while_typing = TRUE)
# the minimum length of prefix to trigger auto completions
options(radian.completion_prefix_length = 1)
# timeout in seconds to cancel completion if it takes too long
# set it to 0 to disable it
options(radian.completion_timeout = 0.05)
# add spaces around equals in function argument completion
options(radian.completion_adding_spaces_around_equals = TRUE)
# automatically adjust R buffer size based on terminal width
options(radian.auto_width = TRUE)
# insert new line between prompts
options(radian.insert_new_line = TRUE)
# the filename that local history is stored, this file would be used instead of
# `radian.global_history_file` if it exists in the current working directory
options(radian.local_history_file = ".radian_history")
# allows user defined shortcuts, these keys should be escaped when send through the terminal.
# In the following example, `esc` + `-` sends `<-` and `esc` + `m` sends `%>%`.
# Note that in some terminals, you could mark `alt` as `escape` so you could use `alt` + `-` instead.
options(radian.escape_key_map = list(
list(key = "-", value = " <- "),
list(key = "m", value = " %>% ")
))
I have tried to use windows terminal:wt which support bracket paste mode, although it need open another window, it may remain convenient with windows terminal:wt quake mode. However, vscode can only send code to the vscode integrated terminal instead of a outer terminal . I can config windows terminal:wt by this setting:
"r.alwaysUseActiveTerminal": true,
"r.bracketedPaste": true,
"r.rpath.windows": "C:\\Yun\\R\\R-4.1.1\\bin\\x64\\R.exe",
"r.rterm.windows": "C:\\Users\\yunyu\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe",
"r.rterm.option": [
"-w",
"_quake",
"new-tab",
"C:\\Users\\yunyu\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\radian.exe",
"--no-save",
"--no-restore",
"--local-history",
"--r-binary=C:\\Yun\\R\\R-4.1.1\\bin\\x64\\R.exe"
],
"r.plot.useHttpgd": true,
"r.session.levelOfObjectDetail": "Detailed",
"r.session.objectLengthLimit": 100,
"r.session.viewers.viewColumn": {
"plot": "Active",
"viewer": "Active",
"view": "Active",
"helpPanel": "Active"
}
Normally, hitting enter on radian would execute the input unless there is a syntax error. If the input is incomplete, radian will insert a new line after the code instead.
However, something unexpected occurred to @Yunuuuu. The + prompt means that at some point radian thinks that the code is executable and passes the input to R, but it really is not. Hence, the + prompt is shown.
I imagine it may be a synchronization issue when a lot of text is "streamed" to R at the same time.
@Yunuuuu What happens if you just copy and paste the code to the radian console on vscode terminal?
Hi randy3k, thanks for your help, but it should run code when I using Ctrl + ENTER to send code to terminal, shouldn't it?
When I paste the code to it, like this:

Both are the results of copy and paste the code? Or just the bottom?
I was asking that to determine if it was an issue introduced by vscode or an issue of radian itself.
Both are pasted into the terminal.
I have tested by coping this code and pasting it multiple times.
if the first pasting comes with a character +, the code after that is always no problem.

if the first pasting comes without a character +, the code (two or more) after that will enter a error eventually.

this seems like these issues?
Awalys has a ")" when submit a function to terminal Extra bracket, }, when sending multiple line for-loop code (from ST to Terminus) Erroneous doubling of closing items and failure to parse input properly Send to terminal doubles closing parentheses
I have tested by coping this code and pasting it multiple times.
Thanks. But it's expected to fail if you just copy and paste multiple times without executing the code.
Though the + sign is concerning, I don't expect to see it when copy and paste.
randy3k, Could it be resolved in windows? I have switched to rterm.exe, but it’s really defective without some elementary features.
Could you reproduce the copy and paste issue in an external terminal outside of vscode? Say powershell or Microsoft Terminal?
they all just correct without any error when implementing the pasting in powershell, cmd.exe, or Microsoft Terminal

I have tried to create radian in vscode using powershell shell, which gave a same problem

So this is the problem of vscode?
I, sometimes, encounter this as well. It's pretty random.
Have to type Enter again in Radian to run the codes that have been sent to run.
Hi everyone. I think I encountered the same problem a while ago and I believe adding options(radian.auto_match = FALSE) to my .Rprofile fixed it for me.
Thanks for telling me that. I have turned radian.auto_match option to FALSE, but it didn't help.
I just realize that it could be a trailing new line issue: see this for discussion.
Could it be fixed? I have tried code with trailing space or without, all of them behave alike. Or can we always send a ENTER operation when sending code in windows? A ENTER operation won't break any code, will it?