REditorSupport / vscode-R

R Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=REditorSupport.r
MIT License
1.07k stars 126 forks source link

Random characters appear when sending code to R #285

Closed renkun-ken closed 4 years ago

renkun-ken commented 4 years ago

From https://twitter.com/MichaelDorman84/status/1252194037064441857.

One issue I encountered is that when sending code to R (not radian) sometimes it also sends unnecessary '1~' or '0~' strings which causes an error...

image

Is there anything we can do about this? I thought we already fixed this.

andycraig commented 4 years ago

I thought we'd fixed this too!

Knowing the OS and r.bracketedPaste setting would be useful.

michaeldorman commented 4 years ago

Thank you very much for the great tools & for looking into this!

OS is:

michael@dell15:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

and VS Code setting are:

{
    "r.bracketedPaste": true,
    "r.alwaysUseActiveTerminal": true,
    "r.sessionWatcher": true,
    "r.rterm.linux": "/usr/local/bin/radian",
    "window.zoomLevel": 1,
    "breadcrumbs.enabled": true,
    "workbench.colorCustomizations": {
        //"editorError.foreground":   "#00000000",
        //"editorWarning.foreground": "#00000000",
        "editorInfo.foreground":    "#00000000"
    },
    "telemetry.enableTelemetry": false,
    "workbench.activityBar.visible": false,
    "workbench.panel.defaultLocation": "right",
    "editor.wordWrap": "on",
    "cSpell.enableFiletypes": [
        "rmd"
    ],
    "cSpell.userWords": [
        "CARTO"
    ],
    "files.associations": {
        "*.geojson": "json"
    }
}
andycraig commented 4 years ago

@michaeldorman Thank you for the info! Bracketed paste mode is basically intended for use with radian only. The R console doesn’t support bracketed paste and when bracketed paste is used with R on Linux/Mac it will produce those junk characters.

I don’t think we really have a way to check whether R or radian is being used in the terminal. So, you pretty much have to switch r.bracketedPaste on or off depending on what you’re using. (Even less convenient than it sounds, because it requires a reload of the extension. It would be good if we could avoid this requirement at least.)

andycraig commented 4 years ago

@michaeldorman Is there a reason you’re using both radian and R? There may be an alternative workaround depending on your use case.

michaeldorman commented 4 years ago

@andycraig I understand, thank you! Will disable the r.bracketedPaste option if necessary.

I'm not yet decided whether to use radian or R. On the one hand, the code highlighting and autocomplete in radian are great. On the other hand, seems like there is slight lag when typing code and also it's confusing to me that when sending a code block the input is printed in one piece and then all outputs follow in another piece (as opposed to seeing alternating input/output lines, like in R).

andycraig commented 4 years ago

@michaeldorman Gotcha! I was wondering if you might be using radian in some projects and R in others. I think enabling/disabling r.bracketedPaste is about the only option unfortunately.

We could potentially change it so that when using bracketed paste the code is sent as several expressions rather than all at once. This would allow for alternating input/output. This is unlikely to happen soon, but it's useful to know that there is interest in that approach.

michaeldorman commented 4 years ago

@andycraig I understand, thank you! Sending the whole code block has other advantages, however, for example being able to go back to a previously executed entire code block with the up/down arrows. So I'm not sure what's better eventually, maybe it's just a matter of getting used to :-)

By they way, one thing I'm missing is being able to send the code from the beginning of the document down to the cursor location (like Ctrl+Alt+B in RStudio). Re-running the script up to the expression being edited is very useful when interactively developing new scripts. (If it's more appropriate that I post this suggestion in separate issue please let me know, will be happy to do that)

andycraig commented 4 years ago

@michaeldorman

By they way, one thing I'm missing is being able to send the code from the beginning of the document down to the cursor location (like Ctrl+Alt+B in RStudio).

Happily, this one would be easy to implement! If you could create a new issue for it that would be great. Thank you!

michaeldorman commented 4 years ago

@andycraig Thanks! I've created a new issue.

andycraig commented 4 years ago

@michaeldorman Thanks for creating the new issue!

I'm going to close this issue, but if you think it should be reopened please let us know.

michaeldorman commented 4 years ago

@andycraig I understand, thank you! Will disable the r.bracketedPaste option if necessary.

I'm not yet decided whether to use radian or R. On the one hand, the code highlighting and autocomplete in radian are great. On the other hand, seems like there is slight lag when typing code and also it's confusing to me that when sending a code block the input is printed in one piece and then all outputs follow in another piece (as opposed to seeing alternating input/output lines, like in R).

OK, it took some getting used to, but now I'm using VS-code with radian at all times! :-)

andycraig commented 4 years ago

@michaeldorman Great to hear! I’m a big fan of radian.