R extension for Visual Studio Code
Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type 'R:' to see list of available commands and shortcuts.
Syntax check is performed as you type or when opening a file. Look for red squiggles. Problems are also reported in the
Extension provides ability to format document or selection. Formatting options are available in the
Automatic formatting (as you type)
The editor can format code after you type Enter, ; or }. You can control the feature via
Functionality is close to lintr. However, you do not have to run linting explicitly, it happens as you type. By default it is disabled, you can enable it by setting
Execute in terminal/source file
Shortcuts and snippets
You can either type
Snippets file can be found in
Thanks to @jackbrookes for suggestions and snippets.
Remoting and WSL
The extension does work in WSL. However, output windows cannot be displayed since UI does not translate over remote connection. There is limited support for plotting though. Remoting like
Using R on Apple ARM silicon
Make sure you install VS Code for OSX for ARM. You may have to download it separately since if you have had VS Code installed on M1 before ARM build became available and kept upgrading it, it is probably still x64. The extension by default uses ARM version with R 4.1 or higher. However, if you need to use Intel build of R such as when you may be using native packages not available for ARM, you can select x64 R from the list of interpreters - such as pick '4.1' and not '4.1-arm64'. Use
Plots typically appear in external R windows. However, there is support for internal
Remember though that Terminal window and internal R session are not connected. Executing code in Terminal and then attempting plot the result via internal session won't work. With remote sessions, you can execute code in Terminal, save results into a file, then execute plotting in internal session providing results from the file.
Using custom R executable in terminal
You can set
R session in the editor does not automatically pick up new packages installed in the terminal. You may have to reload the window for the session to pick up newly installed modules.
R Interpreter not found
Not currently supported
Please file issues at the project GitHub