RMarkdown Code Runner
unlistedby Diego Sánchez Guijarro
Run R code chunks inside Markdown notes like RMarkdown (Rmd). Supports persistent R sessions per note, chunk options, inline plots/tables, persistent markdown outputs, and document knitting.
RMarkdown Code Runner for Obsidian
An Obsidian plugin that executes R code chunks inside Markdown notes, providing an environment equivalent to RStudio, R Markdown (.Rmd), and Quarto.
The plugin provides persistent R execution sessions per note, inline output rendering (text, tables, multi-panel plots, base graphics, and ggplot2), RStudio keyboard shortcuts, contextual autocompletion with Tab support, and document knitting.
Features
Persistent R Session per Note
- Variables, functions, loaded packages (
tidyverse,ggplot2,zoo, etc.), and imported data frames persist in memory across chunks within the note. - The working directory (
setwd()) is automatically anchored to the directory of the active Markdown note, enabling standard relative paths (such asread.csv("01_Data/file.csv")).
Output Rendering
- Plots and Graphics: Renders high-resolution graphics from base R,
ggplot2, and multi-plot arrangements (e.g.gridExtra::grid.arrange()). - Multi-Plot Chunks: Automatically captures and displays all sequential plots produced within a single chunk (e.g., iterative calls to
acf()andpacf()) inside a scrollable output frame. - Structured Data Tables: Automatically formats R
data.frameandknitr::kableobjects into standard Markdown tables. - Diagnostic Badges: Clearly distinguishes errors, warnings, and console messages using dedicated semantic banners without interfering with standard output.
- Silent Setup Chunks: Chunks configured with
include=FALSEexecute silently in the session without generating unnecessary empty containers in the editor, while still surfacing runtime errors if they occur.
RStudio Keyboard Shortcuts
Ctrl + Alt + I(Cmd + Option + Ion macOS): Insert a new R code chunk.Alt + -(Option + -on macOS): Insert assignment operator<-.- Typing
<--: Automatically expands to<-inside R chunks. Ctrl + Shift + M(Cmd + Shift + Mon macOS): Insert native pipe operator|>.Ctrl + Shift + EnterorCtrl + Enter: Execute the active chunk.Ctrl + Alt + P: Execute all chunks above the cursor position.Ctrl + Alt + R: Execute all chunks in the active note.Ctrl + Shift + C: Toggle line or block comments (#).
Autocompletion
- Suggests standard R functions (
print(),paste(),ggplot(),summary(),head(), etc.). - Dynamically indexes variables and datasets defined in the note as you write.
- Suggests chunk options (
echo=FALSE,warning=FALSE,fig.width=, etc.) when editing chunk headers. - Accepts suggestions with either
TaborEnter.
Master Toggle
- A dedicated
Rribbon icon toggles R execution on and off. - When toggled off, all chunk toolbars, output cards, and decorators are suppressed, reverting code blocks to standard Markdown.
Document Knitting
- Knits the active document to HTML, PDF, or Markdown via
rmarkdown::render()using the command palette or shortcut (Ctrl + Shift + K).
Keyboard Shortcuts
| Action | Windows / Linux | macOS | Description |
|---|---|---|---|
| Insert Chunk | Ctrl + Alt + I | Cmd + Option + I | Inserts {r}\n\n at cursor |
| Assign Operator | Alt + - or <-- | Option + - or <-- | Inserts <- |
| Pipe Operator | Ctrl + Shift + M | Cmd + Shift + M | Inserts |> |
| Run Current Chunk | Ctrl + Shift + Enter / Ctrl + Enter | Cmd + Shift + Enter / Cmd + Enter | Executes the active chunk |
| Run All Above | Ctrl + Alt + P | Cmd + Option + P | Executes preceding chunks in order |
| Run All Chunks | Ctrl + Alt + R | Cmd + Option + R | Executes all chunks in the note |
| Toggle Comment | Ctrl + Shift + C | Cmd + Shift + C | Toggles # comment on line/selection |
| Knit Note | Ctrl + Shift + K | Cmd + Shift + K | Knits document to output format |
| Accept Suggestion | Tab or Enter | Tab or Enter | Accepts active autocomplete item |
Chunk Options
Both standard R Markdown chunk header syntax and Quarto #| YAML block syntax are supported.
```{r chunk_label, echo=TRUE, eval=TRUE, include=TRUE, warning=FALSE, message=FALSE, fig.width=7, fig.height=5, fig.cap="Figure Caption"}
# R code
Quarto syntax:
```r
```{r}
#| label: plot-example
#| echo: false
#| fig-width: 8
#| fig-height: 5
#| fig-cap: "Scatterplot"
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
| Option | Values | Default | Description |
| :--- | :--- | :--- | :--- |
| `eval` | `TRUE` / `FALSE` | `TRUE` | Whether to evaluate the chunk |
| `echo` | `TRUE` / `FALSE` | `TRUE` | Display code in knit output |
| `include` | `TRUE` / `FALSE` | `TRUE` | Include chunk output in document |
| `warning` | `TRUE` / `FALSE` | `TRUE` | Display warning messages |
| `message` | `TRUE` / `FALSE` | `TRUE` | Display console messages |
| `results` | `"markup"` / `"asis"` / `"hide"` | `"markup"` | Text output format mode |
| `fig.width` / `fig-width` | Numeric (inches) | `7` | Figure width |
| `fig.height` / `fig-height` | Numeric (inches) | `5` | Figure height |
| `fig.cap` / `fig-cap` | String | `""` | Figure caption |
---
## Output Storage Modes
Configurable under **Plugin Settings**:
1. **Dynamic UI Only (Default)**: Outputs are rendered dynamically in the editor interface without writing to the `.md` file.
2. **Persist into Markdown File**: Outputs and generated images (in `rmd-plots/`) are written directly to the file inside `<!-- rmd-output:start -->` and `<!-- rmd-output:end -->` tags.
3. **Both**: Combines interactive UI widgets with persisted Markdown blocks.
---
## Installation
### Prerequisites
- R 4.x installed locally. The plugin automatically searches default installation paths (Windows registry and standard directories, `/usr/bin/Rscript`, `/usr/local/bin/Rscript`, Homebrew), or a custom path can be specified in settings.
### Manual / Local Build
1. Clone the repository into your vault's plugins folder:
```bash
cd <VaultFolder>/.obsidian/plugins/
git clone https://github.com/diegosg-dev/CodeRunnerObsidian.git
cd CodeRunnerObsidian
npm install
npm run build
- In Obsidian, open Settings → Community plugins and reload installed plugins.
- Enable RMarkdown Code Runner.
Development
# Install dependencies
npm install
# Run integration tests
npm test
# Build production bundle
npm run build
# Watch mode
npm run dev
Author
Diego Sánchez Guijarro (@diegosg-dev)
License
This project is licensed under the MIT License.
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.