RStudio - selected code to snippet - updating r.snippets programmatically

rstudio
snippets

#1

I like using the RStudio snippets.

I thought it would be great, if i can select code and add it to the snippets by keyboard shortcut.

So i started working on it.

Even if I edit the r.snippets file programmatically, the created snippet seems only to be updated if the r.snippets file will be
opened afterwards (in RStudio). As a workaround i call file.edit("~/.R/snippets/r.snippets") at the end of the code.

My questions:

  1. Does the file have to be opened or can the changes be recognised by RStudio in another way as well?
  2. Would it be better practise to directly navigate to the
    a) modalDialog() like in my example? (assuming the r.snippets file does not have to be opened)
    b) or directly paste the selected code in the r.snippets file?

#2

RStudio doesn't directly monitor the snippets files, so editing them directly isn't enough to trigger RStudio to re-read and re-apply snippets. The simplest way to synchronize state here is to restart the IDE.