Inserting a custom snippet via a shortcut in an R markdown/Quarto document

I'm working on a package that can inject author data in Quarto documents. I'd like to allow users to create a place holder to insert some data in a specific location in the document. I can easily modify the Quarto document using a function in an external script. However, I'd ideally prefer to insert the place holder directly from the IDE using a shortcut (similar to Ctrl + Alt + I/Cmd + Option + I to insert a code chunk in R markdown). I presume the code chunk shortcut is integrated in RStudio but is it possible to implement such snippet/shortcut in a custom package?

I'm aware of addin and rstudioapi::insertText(). It's not really what I want though because that only executes a function via a shortcut so it can't be used to insert the place holder in an R markdown document directly.

I'm asking out of curiosity, if that's doable but hard to implement, I'll simply use a normal function.

I would have think that addins would allow you to do what you want, but I may have missed the real case.

Otherwise, you have snippets that could be of help
https://rstudio.github.io/rstudio-extensions/rstudio_snippets.html

Thanks for the suggestion. Maybe I'm the one who missed something but from what I tried, I could only run the addin in a code chunk, not outside of it. Same for snippets.

In the end, I'll use a different approach.

You should be able to run addin in Markdown document like .qmd . This addin does work with Rmd for example

For snippets you need to add into the Markdown syntax snipper, and not the R files. Did you do that ?

Then I think it should work, but maybe without auto completion. You need to type the snippet name and then trigger the snippet insertion (check keyboard shortcut as maybe there is no shortcut assign to the completion). You can use command palette for this too.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.