Integrating R Markdown into Obsidian Workflow

If you’re like me, you write lecture notes in R markdown and have been looking for a way to integrate it into your Obsidian workflow. Until recently, the necessary plugin support just hasn’t existed, but I think I’ve now found a workable solution. If you have a different setup, please share it!

Required Plugins

Note: as of writing, the Custom File Extensions Plugin has not gone through code review, so you will need to manually install it. However, I believe there may exist other plugins with the same functionality.

Configuration

  1. In the settings for the Custom File Extensions Plugin, add “rmd” to the list of file types. This will assign the in-app markdown view to all R markdown files in your vault. Note that code blocks defined with {r} will still have syntax highlighting in reader view, but not editor view.
  2. Go to the R language-specific settings for the Execute Code plugin and set the path to your Rscript installation.
  3. Enable “Run R blocks in Notebook Mode.” This will allow each code block that you select to execute in the same environment.
  4. (Optional) Enable “Embed R plots created via plot() into Notes.” Currently, plot() is the only function that is allowed to embed graphics into your note, but there are some workarounds. For instance, if you use ggplot2, just do plot(ggplot_object).
  5. (Optional) Load your most used libraries in the “Inject R code” box. These libraries will now be added to the top of every code block you execute.

Example

4 Likes