Obsidian and R workflow

Anyone else use R for data analysis?

Many of my notes deal with R code, statistical methods, and the subjects that I’m analyzing (environmental science). Theory, application, tips, and examples are interlinked, so Zettelkasten seems like a good approach for thinking through it. R also support a similar flavor of Markdown, complete with LaTeX math and folding, so Obsidian seems like a good fit for maintaining my knowledge base!

Going from Obsidian to R Studio, the only issues I’ve run into are

  • There needs be a blank line before headers, block quotes, bullet points, and lists, or they won’t render
  • Embedded images are supported ![caption](image.jpg), but you need to copy the images to the R project folder, and may need to edit the relative path if you’ve put them in a subfolder ![caption](images/image.jpg)
  • Double bracket links and hashtags can’t be used for navigation, but don’t break anything. Just need to do a search and replace to clean them up.
  • Transclusion won’t work
  • Footnotes are not supported

Going from R Studio to Obsidian

  • embedded images need to be copied to the attachments folder, and relative path corrected
  • Code blocks are a little harder to read without syntax highlighting
  • yaml header displays as a level 1 heading

For writing a report or academic paper, a possible workflow is to assemble an outline in Obsidian with relevant background info, citations, and some generic code snippets I think might come in handy. The results section would get fleshed out in R Studio, as I work with the data.

9 Likes

To answer your question, I use R quite a bit. But I’m still evaluating Obsidian.

One other point, I footnotes are allowed in Rmarkdown.^[See Sec. 2.5.1 in R Markdown: The Definitive Guide].

2 Likes

hi comandra,

i’m also working in environmental science and also depend heavily on R for data analysis. i dug into the whole obsidian/zettelkasten universe earlier this year only.

i was wondering when reading your question about the file-links - are you separating your rstudio projects and your obsidian vault?

at the moment i’m doing so, but as the vault also contains information related to the project that the RStudio-Analysis is based in, I’m noticing more and more that the division of information of those two is not helpful for keeping the overview. my compromise at the moment looks like this: (semi-automatically) synchronizing my Rstudio-“Results/Plot”-folder to the Obisidian vault to make it possible to embed plots in notes with the proper file path.

3 Likes

Hi everyone! I have also been struggling with this workflow and appreciate the comments. Paulge, I wonder if you have tried adding GitHub to the mix. This may sound cumbersome for those who are not familiar with Git and GitHub. However, as a novice, I can tell you it is easier to catch up than I thought. This is something that I’m trying right now and it seems to work:

  1. Create a repository in GitHub for your project (i.e. research paper).
  2. Install GitHub desktop to make a local copy of your repository on your computer.
  3. Create your “R Project” and link it to your repository using version control.
  4. Create (move a copy?) of your Obsidian Vault into the same local GitHub/R project folder.
  5. Start editing your obsidian notes in RStudio Or Obsidian and everything will be up to date.
  6. “Push” your changes into your repository.
  7. Your own ingredients to this recipe…

As I said, I’m testing this solution right now, and it passed the first test: Creating and editing notes alternatively in RStudio or Obsidian and being able to “Push” those changes to my repository in GitHub.

I haven’t tried these ones yet, but my hypotheses are:
You should not have to deal with relative paths for images.
The integration between Zotero, Better Bib Text, and R markdown should be seamless.

I’m curious about what could happen with code blocks. This is what I found in another forum: Handle (edit) other plain text file formats ( rmarkdown, tex, txt, code, etc ).

My plan is to use Obsidian for knowledge management (bibliography, etc) and knowledge exchange (network analyses) and keep the portions with code chunks as Rmd files.

4 Likes

I work with multiple projects, and with R and Python. These scientific research projects, often includes very heavy analysis, that often sifts through large size of data, from GB to TB.

I personally separate R and Python projects with Obsidian. The thousands of plots (particularly when starting a project to get an overview of the data, or differences in analysis methods) I made, would overwhelm Obsidian Vault. Not including many files, raw data, supplementary data, and other analysis using other programs (such as 3D/4D image plotting). As one project progress, many of these plots and analysis becomes redundant, but I prefer not to remove them. Often an outsider would point out something in my analysis, that would make me review some of these building up materials.

I have been thinking, in order to facilitate Markdown document between R environment and Obsidian, there are several things I should make sure happens. This point of view is to prioritise Obsidian notes over R workflow. Once basic analysis script, specific analysis script is done, I would create a R markdown document (or Quatro) which will be saved in Obsidian Vault, but remembered by RStudio and RProject. If pictures/plots are created, it will be saved in Obsidian Vault. If the Rmd/Qmd files need to refer to certain plots, those plots should stay in Obsidian Vault instead of R project.

1 Like

I indeed also use a git system for backup/versioning.

Looking back on my post from earlier, I fear I didn’t improve much on any of the issues reported here. I did however, write my first publication using Quarto/RMarkdown but crashed into the MS Word barrier with my collaborators. However, due to lack of discipline and time, i didn’t improve much on the obsidian integration of this process… :frowning:

In the meantime, I came across an interesting reddit post that I wanted to share. It contains the whole workflow we were talking about!

Awesome discoveries and workflow.
I just have one question: for every R project then, you have an independent Obsidian vault to document it?