R Notebook for VS Code opens R Markdown (.rmd) and Quarto (.qmd) files as VS Code notebooks. Filename extension matching is case-insensitive. It gives each notebook an inline R session and shows R results and plots below code cells while keeping the document in its original file format.
The notebook renders only the minimal information from .rmd and .qmd files needed to support the inline R session and display Markdown cells. It does not provide full R Markdown or Quarto rendering. Use the normal R Markdown or Quarto render workflow when you need a complete HTML, PDF, Word, or other published document.
- Run R code cells with inline results, plots, and table previews.
- Use a separate R session for each notebook.
- Start the notebook's R session automatically when it becomes active.
- Display Markdown cells with headings, references, and inline R results.
- Edit cell labels and options from the cell toolbar.
- Show suggestions based on installed R and Quarto tools and notebook content.
- Send code cells to R Console for VS Code.
- Save and restore outputs with an optional
.r-notebooksidecar file. - Connect the active session to vscode-R viewers.
-
Install R.
-
Install
knitr1.44 or newer andrmarkdown:install.packages(c("knitr", "rmarkdown"))
-
On Windows, install
psto cancel a cell without stopping its R session:install.packages("ps") -
Install
bookdownwhen an R Markdown document uses abookdown::output format. -
Install vscode-R.
-
Install R Console for VS Code.
-
Configure the vscode-R path for your platform:
- Windows:
r.rpath.windows - macOS:
r.rpath.mac - Linux:
r.rpath.linux
- Windows:
-
Alternatively, make R available through
R_HOMEorPATH. -
Install the Quarto CLI for
.qmdnotebooks. -
Set
r.notebook.quartoPathif Quarto is not on the R session'sPATH. -
Make Pandoc available to
rmarkdownfor R Markdown-cell display. -
Trust the VS Code workspace before running local R code.
- Open a file from the Explorer with Open as R Notebook.
- Use Reopen Editor With... and choose R Notebook Editor when needed.
- Save normally to write changes back to the original
.rmdor.qmdfile. - Use the notebook run buttons to run one or more cells.
- Use Run Cell in R Console to send a cell to the interactive R Console.
- Select the gear button on a code cell to edit its label and options.
- Use Merge to header or Merge to pipe to combine R Markdown options.
- Treat
#|pipe values as the winner when R Markdown options conflict. - Store Quarto cell options in
#|pipe lines.
- Use Restart R to start a fresh session.
- Use Shutdown and Close to close the notebook and stop its R process.
- Keep a closed notebook's session for 15 minutes by default.
- Use R Notebook: Reopen Running Notebook Session... to reopen a retained session.
- Set
r.notebook.sessionShutdownDelayMinutesto0to disable automatic shutdown.
-
Run inline code and display Markdown cells without the vscode-R session watcher.
-
Enable both settings to use vscode-R's managed
sessAPI for workspace, data, and help viewers:"r.sessionWatcher": true, "r.notebook.rExtensionIntegration": true
-
Reload the VS Code window after changing either setting.
-
Notebook session attachment uses vscode-R's public
session.prepareAttachment()andsession.activate()APIs, with its managedsesspackage. First-time installation may require consent. -
Use a vscode-R version supporting these APIs (v3.2.0 or later).
-
Disable
r.notebook.rExtensionIntegrationto run without vscode-R session integration.
R code cells use the R languageserver package for completion, hover, signature help,
diagnostics, navigation, rename, formatting and other supported LSP features. Install
it in the configured R environment with install.packages("languageserver").
The notebook starts a separate language-server process for each open notebook and
stops it when the notebook closes. It uses vscode-R's R executable resolver and the
r.lsp.args, r.lsp.lang, r.lsp.debug, r.lsp.diagnostics, r.libPaths and
r.useRenvLibPath settings. Set r.lsp.enabled to false
to disable it. Language features do not require the notebook's execution session
to be attached. Startup errors appear in R Notebook Language Server output.
Cells use the R (Notebook) language mode, sharing vscode-R's R syntax grammar.
This keeps notebook requests separate from vscode-R's text-editor providers;
saved documents still contain ordinary {r} chunks. Editor settings specific to
this mode can be placed under [r-notebook-r].
| Setting | Default | Purpose |
|---|---|---|
r.notebook.quartoPath |
"" |
Sets the Quarto executable path |
r.notebook.saveState |
true |
Saves and restores output in a .r-notebook sidecar file |
r.notebook.rExtensionIntegration |
true |
Connects the active notebook session to vscode-R |
r.notebook.sessionShutdownDelayMinutes |
15 |
Retains a closed notebook's R session for this many minutes |
- Disable
r.notebook.saveStateto ignore existing sidecar files and stop creating new ones.
- vscode-R — Provides the R path and optional viewer integration.
- R Console for VS Code — Provides interactive console execution.
knitr1.44 or newer andrmarkdown— Support execution and Markdown-cell display.- Quarto CLI — Supports
.qmdnotebooks. pson Windows — Interrupts a cell without stopping its session.bookdownwhen required — Supportsbookdown::R Markdown formats.
Run npm run test:integration to test the language service in an isolated VS Code
profile using the installed R extensions and a real R language server. Set
VSCODE_EXECUTABLE to the VS Code executable (for example, Code.exe on Windows).
Optionally set R_EXECUTABLE and VSCODE_EXTENSIONS_DIR. The test covers .rmd
and .qmd cells, edits, language features, URI mapping and ordinary R documents.
Set R_LSP_MULTI_SERVER=true to also exercise vscode-R's multiple-server mode.
This extension's source code was written with assistance from GPT models using OpenAI's Codex. The overall feature design and logic decisions are mine; GPT models were used to generate and iterate on the implementation.
- MIT