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
- 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. - Go to the R language-specific settings for the Execute Code plugin and set the path to your Rscript installation.
- Enable “Run R blocks in Notebook Mode.” This will allow each code block that you select to execute in the same environment.
- (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 useggplot2
, just doplot(ggplot_object)
. - (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.