Skip to content

torbjorn/vscode-R

 
 

Repository files navigation

R Extension for Visual Studio Code (Fork)

Badge

Important

This is a fork of the original R extension that adds configurable working directory support for R processes.

What's New in This Fork

This fork implements the feature requested in issue #1634:

  • New setting: r.workingDirectory - Configure where R processes start
  • Flexible project structure: R Language Servers and terminals can run from subdirectories
  • renv support: Perfect for projects with renv.lock files in subfolders
  • Complex projects: No need to restructure your entire project layout

Use Cases

  • Projects with R code in subdirectories (e.g., src/analysis/, R/)
  • renv environments not in the workspace root
  • Multi-language projects where R is just one component
  • Monorepos with multiple R projects

Configuration Examples

Add this to your VS Code settings.json:

{
  "r.workingDirectory": "${workspaceFolder}/src/r-analysis"
}

Variable substitution supported:

  • ${workspaceFolder} - Current workspace root
  • ${userHome} - User home directory
  • ${fileWorkspaceFolder} - Workspace folder of currently active file
  • ${fileDirname} - Directory of currently active file

Example configurations:

// For renv projects in subdirectories
{
  "r.workingDirectory": "${workspaceFolder}/analytics"
}

// For projects where R files are in a specific folder
{
  "r.workingDirectory": "${workspaceFolder}/src/R"
}

// Dynamic: use the directory of the current file
{
  "r.workingDirectory": "${fileDirname}"
}

About the R Extension

This VS Code extension provides support for the R programming language, including features such as R language service based on code analysis, interacting with R terminals, viewing data, plots, workspace variables, help pages, managing packages, and working with R Markdown documents.

The R and R Markdown syntaxes are located in a slibing package vscode-R-syntax.

Go to the wiki to view the documentation of the extension.

Getting started

  1. Install R (>= 3.4.0) on your system. For Windows users, Writing R Path to the registry is recommended in the installation.

  2. Install languageserver in R.

    install.packages("languageserver")
  3. Install the R extension for VS Code from the VS Code Extension Marketplace or the Open VSX Registry.

  4. Create an R file and start coding.

The following software or extensions are recommended to enhance the experience of using R in VS Code:

  • radian: A modern R console that corrects many limitations of the official R terminal and supports many features such as syntax highlighting and auto-completion.

  • VSCode-R-Debugger: A VS Code extension to support R debugging capabilities.

  • httpgd: An R package to provide a graphics device that asynchronously serves SVG graphics via HTTP and WebSockets.

Go to the installation wiki pages (Windows | macOS | Linux) for more detailed instructions.

Features

Questions, issues, feature requests, and contributions

  • If you have a question about accomplishing something in general with the extension, please ask on Stack Overflow.

  • If you find a problem or have a feature request with the extension, please find out if there is a current issue you may upvote or otherwise file an issue.

  • Contributions are always welcome! Please see the contributing guide for more details.

About

R Extension with configurable starting directory

Resources

License

Contributing

Stars

Watchers

Forks

Languages

  • TypeScript 82.4%
  • R 10.8%
  • CSS 5.3%
  • Other 1.5%