Roger J Bos CFA
Roger J Bos CFA

Reputation: 504

VS code mangles command when sending selection to R

When I open a .R file and highlight a line and press Shift + Enter, VS code sends the line to R, but it mangles the text. For example, if I try to run

library(data.table)

Here is what I get back from R:

> 00~library(data.table)01~
Error: unexpected numeric constant in "00~library(data.table)01"

Strangest thing. VS Code works fine for me for Go, Typescript, Haskell, Python, but it doesn't like R. Any suggestions?

Upvotes: 3

Views: 880

Answers (2)

Gabi
Gabi

Reputation: 1343

This output shows that you're not getting the radian terminal, even though it's installed. You're getting the plain R terminal. As of this writing, VS Code settings are split between User and Workspace. Bracketed paste mode should be on (true) in both, and Rterm should be set to the radian path in both. That's what fixed this error for me. Otherwise, Workspace takes precedence over User. If Rterm is set to the plain R binary in Workspace, you get a plain R terminal when you execute a line form a script. This error shows that R misinterprets the first line number (00) as an unexpected numeric constant; radian would not. The cursor would look different too -- r$> instead of > as shown in this example.

Upvotes: 0

andycraig
andycraig

Reputation: 870

It looks like bracketed paste mode is on. Try adding this to your settings.json:

"r.bracketedPaste": false

Bracketed paste mode should usually be on if using the radian console but off if using the standard R console.

Upvotes: 1

Related Questions