Search code examples
rvisual-studio-coderstudio

R workspace doesn't load anything in Visual Studio Code


enter image description here

I'm new to R and currently using vscode for it. i wanted it to show environment and plot like in RStudio, but the workspace just stayed empty after i ran the code. Is there some settings needs to be changed or packages to be install to solve this?

I followed the setting up instructions on vscode website and installed package 'languageserver' and 'httpgd', package 'radian' was said to not available for my version of R (4.3.1)

i expected it to show environment and plot like in RStudio.

enter image description here


Solution

  • It looks like you ran the whole file in a bash terminal and got only the printed output. Instead, try adding a new R terminal and then running the code - use CTRL + SHIFT + P and then select "R: create terminal". You could also run each line of an R file using CTRL + ENTER - this will automatically create an R terminal and run the line of code corresponding to your cursor.

    If you run code as described here, the plots will show up similarly to RStudio. You can view the variables in your environment with the workspace viewer that is part of the VSCode R extension (thanks @margusl for this addition).