Skip to content
R Extension for Visual Studio Code (execution, snippet, lint, R documantation, R Markdown)
TypeScript R JavaScript
Branch: master
Clone or download
andycraig Merge pull request #184 from renkun-ken/update-readme
Improve session watcher initialization
Latest commit 625ae35 Jan 24, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Jan 17, 2020
.vscode fix dependency and lintr Jun 20, 2018
R Merge pull request #184 from renkun-ken/update-readme Jan 24, 2020
images Add R session watcher section to README.md Dec 15, 2019
snippets fix snippets Jan 18, 2018
src Respect existing R_PROFILE_USER Jan 24, 2020
syntax Fix function call closing bracket highlight Dec 11, 2019
test add roxygen comments Sep 29, 2019
.gitignore .gitignore is now working Apr 16, 2019
.vscodeignore refactor and add webpack Apr 15, 2019
CHANGELOG.md version 1.2.1 Jan 13, 2020
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Sep 5, 2017
CONTRIBUTING.md fix document style Nov 23, 2017
ISSUE_TEMPLATE.md Add opt-in r.sessionWatcher option Dec 15, 2019
LICENSE fix LICENSE to MIT Nov 18, 2019
PULL_REQUEST_TEMPLATE.md Create PULL_REQUEST_TEMPLATE.md Jan 8, 2019
README.md Update README.md Jan 24, 2020
package-lock.json Initial implementation of plot history Jan 13, 2020
package.json
r-configuration.json support code region Nov 23, 2017
rd-configuration.json fix grammer based on atom Mar 21, 2018
tsconfig.json fix depencency Dec 9, 2018
tslint.json update some dependencies Mar 21, 2018
webpack.config.js Update plot history WebView and resources Jan 13, 2020

README.md

R support for Visual Studio Code

Requires R.

Usage

  • For Windows, set config r.rterm.windows to your R.exe Path like "C:\\Program Files\\R\\R-3.3.4\\bin\\x64\\R.exe";
  • For Radian console, enable config r.bracketedPaste
  • Open your folder that has R source file (Can't work if you open only file)
  • Use F1 key and R: command or Ctrl+Enter(Mac: ⌘+Enter)

Features

  • Run Source(Ctrl+Shift+S or Push iconicon) and Run Selected Line (Ctrl+Enter)
  • Run nrow, length, head, thead, names functions (Ctrl + 1, 2, 3, 4, 5)
    • If you are using Mac Ctrl to

use Run .R

  • R Integrated Terminal

Create R terminal

  • Run code in terminal containing existing R session, for example over SSH (Run Selection/Line in Active Terminal)
  • Run all commands in terminal containing existing R session (enable config r.alwaysUseActiveTerminal)

R over SSH

  • Extended Syntax(R, R Markdown, R Documentation)

Syntax

  • Create .gitignore based R.gitignore

  • Data frame viewer and Environment viewer(Preview Data frame or Preview Environment)

Image

  • Snippets

  • Package development short cut (Load All, Test Package, Install Package, Build Package and Document)

Requirements

Extension Settings

This extension contributes the following settings:

  • r.rterm.windows: set to R.exe path for Windows

  • r.rterm.mac: set to R term's path for Mac OS X

  • r.rterm.linux: set to R term's path for Linux

  • r.rpath.lsp: set to R.exe path for Language Server Protocol

  • r.rterm.option: R command line options (i.e: --vanilla)

  • r.source.encoding: An optional encoding to pass to R when executing the file

  • r.source.focus: Keeping focus when running (editor or terminal)

  • r.alwaysUseActiveTerminal: Use active terminal for all commands, rather than creating a new R terminal

  • r.bracketedPaste: For consoles supporting bracketed paste mode (such as Radian)

  • r.sessionWatcher: Enable R session watcher (experimental)

  • Language server(developing here)

R Session Watcher (Experimental)

This experimental feature is still under development and the behavior may change without notice. Please file an issue here if you experience problems or have any suggestions.

An opt-in experimental R session watcher is implemented to support the following features:

  • Watch any R session
  • Show value of session symbols on hover
  • Provide completion for session symbols
  • View() any objects including data frames and list objects
  • Show plot output on update and plot history
  • Show htmlwidgets, documentation and shiny apps in WebView

Basic usage

To enable this feature, turn on r.sessionWatcher in VSCode settings, reload or restart VSCode, and the session watcher will be activated automatically on R sessions launched by vscode-R via R: Create R Terminal command.

If you previously appended the source(...) line to ~/.Rprofile, you may safely remove it since the configuration for basic usage is automated. It is now only necessary for advanced usage described below.

Advanced usage (for self-managed R sessions)

For advanced users to work with self-managed R sessions (e.g. manually launched R terminal or started in tmux or screen window), some extra configuration is needed. Follow the steps below to make R session watcher work with any external R session:

  1. Turn on r.sessionWatcher in VSCode settings.

  2. Edit .Rprofile in your home directory by running the following code in R:

    file.edit("~/.Rprofile")
  3. Append the following code to the file:

    source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
  4. Restart or Reload Window in VSCode

If the workspace folder you open in VSCode already has a .Rprofile, you need to append the code above in this file too because ~/.Rprofile will not be executed when a local .Rprofile is found.

The script only works with environment variable TERM_PROGRAM=vscode. the script will not take effect with R sessions started in a tmux or screen window that does not have it, unless this environment variable is manually set before sourcing init.R, for example, you may insert a line Sys.setenv(TERM_PROGRAM="vscode") before it.

How to disable it

For the case of basic usage, turning off r.sessionWatcher in VSCode settings is sufficient to disable R session watcher.

For the case of advanced usage, user should, in addition, comment out or remove the source(...) line appended to ~/.Rprofile.

How it works

This script writes the metadata of symbols in the global environment and plot file to ${workspaceFolder}/.vscode/vscode-R/PID where PID is the R process ID. It also captures user input and append command lines to ${workspaceFolder}/.vscode/vscode-R/response.log, which enables the communication between vscode-R and a live R sesson.

Each time the extension is activated, the latest session watcher script (init.R) will be deployed to ~/.vscode-R/init.R.

R sessions started from the workspace root folder will be automatically attached. The session watcher is designed to work in a wide range of scenarios:

  • Official R terminal or radian console
  • R session started by vscode-R or user
  • R session in a tmux or screen window
  • Switch between multiple running R sessions
  • Remote Development via SSH, WSL and Docker

The status bar item shows the process id of the attached R session. Click the status bar item and it will attach to currently active session.

Attached R process

R session watcher

The R terminal used in the screenshot is radian which is cross-platform and supports syntax highlighting, auto-completion and many other features.

TODO

  • Debug

CONTRIBUTING

This extension based on

Collaborators

I hope you will join us.

FAQ

  • Q: I can't use command and message is xxx no command found.
  • A: Please open your folder that has R source file

The R logo is © 2016 The R Foundation

You can’t perform that action at this time.