I've created a basic RMarkdown template in an internal custom themes package. The template shows up as expected in RStudio (currently running build 1.2.907). I'd love to assign a keyboard shortcut to open a new file based on this template, akin to the custom keyboard shortcut that can be assigned to the "New R Notebook" command. There doesn't seem to be a way to access any of the template's for shortcuts, short of creating a custom add in and assigning a shortcut to the add in.
That's doable, but is more work than I really wanted to take on. Is there a more direct way of accomplishing this end (having a keyboard shortcut that creates a new notebook based on a package supplied template)?
Reading through https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets, I'm not sure this gets me where I need to go - which is to allow R users across my org to install our mycothemes package and have access to our ggplot theme, fonts, color palette, and RMarkdown templates. Specifically, how would a snippet call a package installed Markdown template? If that was overcome, there would still be the issue of distributing files into every user's .R/snippets, right?
Appreciate the thought! Please let me know if I'm overlooking features in snippets for this use case!
This part sounds like a regular package that you could distribute in a few different ways, see e.g.
The second part, of creating a template and a shortcut could be accomplished by making an RStudio addin, which could be part of your package or separate, it's just a matter of preference. You can assign keyboard shortcuts to addins, which would, in effect, allow you to have a shortcut for your template (I think).
The closest thing that comes to mind is the New Post option in blogdown, which you can select from the addins dropdown (and, if so desired, add a keyboard shortcut to open it).
Hopefully some of these resources can get you started! I've never made an addin, but there are lots of good examples in this thread, as well as a webinar which I've also linked to, below.
A limitation of this method is that it forces a different user experience than the standard RStudio new R Script/R Markdown workflows by requiring a file to be created on disk with either an add-in or user specified name. The native RStudio New... experience creates an unsaved Untitled file and leaves the location and name of the file up to the user. One may argue that not permitting unsaved Untitled files is a feature and not a bug () but given the threads that keep occurring on changing the current RMarkdown cars based template, I'm surprised allowing organizations to roll out their own standard look and feel for analysis and reports is so difficult.
Really, all I needed was the ability to (manually) specify a shortcut to a specific RMarkdown template that already appears in the RStudio window. This works though!
Yeah, I hear you. By making a template, you can select it when you go File >> New R Markdown, but (to my knowledge) there isn't a shortcut for that. You can feel free to submit this as a feature request (FR) for the IDE
I'd recommend keeping the FR to the more general use-case of creating a new RMarkdown file, since it's apt to be helpful to more people.
It's also possible that you could write an addin such that it would create an unsaved unnamed file. (Again, I have no experience there). Yihui's add-in was just a possible starting point.
Definitely keep us updated if you figure something out, I for one would love to know if this was possible!