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

Multi-line code not running with R.

Open mcwayrm opened this issue 7 months ago • 4 comments

Describe the bug When I go to run an R script in vscode, I am able to run line which span only a single line. But if it spans a second line (e.g., a command inside ( ) or using +) I am unable to complete the command. I just got a new computer and am able to perform this with the same setup on a Dell Windows 10, but somehow I have issues with an LG Windows 11. The vscode environment is identically set up.

For example, I can import the data but I am unable to run this regression:

# Load data 
df <- setDT(import(path_data))
# Run Regression
col1 <- plm(publish ~ low + exlow + exhigh + field + phd + unilow + pval, 
                data = df,
                index = c("id", "vignette"), 
                model = "within")

Rather, I get the following error message:

Image

I have checked my settings.json and I believe everything should be in order:

"r.rpath.windows": "C:\\Program Files\\R\\R-4.4.3\\bin\\x64\\R.exe",
"r.rterm.windows": "c:\\Users\\user\\miniforge3\\envs\\env\\Scripts\\radian.exe",
"r.libPaths": [
    "C:\\Program Files\\R\\R-4.4.3\\library"
    ],
"r.plot.useHttpgd": true,
"r.bracketedPaste": true

To Reproduce Taking any command I will be able to complete the first line but not the second line within vscode:

# Data 
data <- cars
# Works
reg1 <- lm(speed ~ dist , data = data)
# Does not work 
reg2 <- lm(speed ~ dist , 
                  data = data)

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

No

Expected behavior I expect both commands to run regardless if I press enter and move part of the command to the next line.

Environment (please complete the following information):

  • OS: Windows 11
  • VSCode Version: 1.99.3
  • R Version: 4.4.3
  • vscode-R version:

mcwayrm avatar Apr 16 '25 20:04 mcwayrm

I have the same issue when run R: Run Selection Line

pacman::p_load(
  data.table, dplyr, lubridate
)

vscode terminal give errors:

r$> pacman::p_load()
Error in match.call(expand.dots = FALSE)[[2]] : subscript out of bounds
r$>   data.table, dplyr, lubridate
Error: unexpected ',' in "  data.table,"
r$> )
Error: unexpected ')' in ")"

kongdd avatar Apr 18 '25 07:04 kongdd

So, I found a solution to my problem that resolved my issue. I still think there is some bug in the radian package though (not sure who to raise this to.

For me, the solution was to stop using radian, and instead us the base R by changing my user preferences in the JSON file:

"r.rpath.windows": "C:\\Program Files\\R\\R-4.4.3\\bin\\x64\\R.exe",
// Added this
"r.rterm.windows": "C:\\Program Files\\R\\R-4.4.3\\bin\\x64\\R.exe",
// Commented this out
// "r.rterm.windows": "c:\\Users\\user\\miniforge3\\envs\\env\\Scripts\\radian.exe",

The base R and radian appear to do the same thing in vscode. Radian just seems to add some functionality but does not change the performance.

mcwayrm avatar Apr 18 '25 13:04 mcwayrm

This solution works for me. https://github.com/REditorSupport/vscode-R/issues/1590#issuecomment-2717388826

options(radian.auto_match = FALSE)
options(radian.auto_indentation = FALSE)

write into .Rprofile or .radian_profile. Then restart

kongdd avatar Apr 19 '25 10:04 kongdd

This solution works for me. #1590 (comment)

options(radian.auto_match = FALSE) options(radian.auto_indentation = FALSE) write into .Rprofile or .radian_profile. Then restart

It works for me.

gynecoloji avatar Jun 12 '25 05:06 gynecoloji

This solution works for me. #1590 (comment)

options(radian.auto_match = FALSE) options(radian.auto_indentation = FALSE) write into .Rprofile or .radian_profile. Then restart

You are the saviour!

OndrejMottl avatar Jul 21 '25 11:07 OndrejMottl

This solution works for me. #1590 (comment)

options(radian.auto_match = FALSE) options(radian.auto_indentation = FALSE) write into .Rprofile or .radian_profile. Then restart

thanks!!!!

wwowo avatar Jul 30 '25 11:07 wwowo

This solution works for me. #1590 (comment)

options(radian.auto_match = FALSE) options(radian.auto_indentation = FALSE) write into .Rprofile or .radian_profile. Then restart

This worked for me !!

aseembh2001 avatar Nov 07 '25 20:11 aseembh2001