0

I have an R markdown template (skeleton.Rmd and template.yaml) that I would like to use. The various documents that describe the creation of templates (e.g., here, here, and here) all say that templates are either created in the working directory (e.g., by using the use_rmarkdown_template() function) or in the inst/rmarkdown/templates directory of a package (I assume the package your are developing).

I work on a Mac, and my working directory is usually the Desktop (I know - someone is going to say this is bad for whatever reason, but it's the way my broken brain works), and I don't want the inst/rmarkdown/templates directory on the Desktop.

I have a large number of templates installed (i.e., that are available from File -> New File -> R Markdown -> From Template), but I cannot seem to find anything related to those names when I search for them.

EDIT: Here is a solution that works. I don't know if it's kosher or not, but I get the behavior I'm after.

The path is: Library/Frameworks/R.framework/Versions/[*note1*]/Resources/library/rmarkdown/rmarkdown/templates/[*HERE*]

Note 1: If you have multiple versions of R installed, pick the right one. I'm not sure if "Current" works or not. Obviously no brackets or asterisks.

Note 2: The double rmarkdown/rmarkdown is not a typo.

At this point, you take the directory that contains just your template (i.e., the template.yaml file and the subdirectory called skeleton with the file skeleton.Rmd in it) and put it where I put HERE (again, no brackets or asterisks).

Restart R. When you open a new markdown file, your template will be available in the list - no unique working directory and no package.

If anyone knows of problems with this, please let me know. Otherwise, I think we should propagate this! (I don't have a solution for Windows, but I'm sure it would be similar.)

Karl Wolfschtagg
  • 425
  • 2
  • 10
  • 1
    You need to create your own package to have a custom template. When you create your package, that's where the `inst/markdown/templates` folder will go. Perhaps this existing answer will give you more info: https://stackoverflow.com/questions/57361395/creating-templates-in-rmarkdown – MrFlick Mar 10 '22 at 17:28
  • I saw that before I posted. When you install other templates (which don't require a package or a working directory), where do they go? – Karl Wolfschtagg Mar 10 '22 at 17:34
  • 1
    There are no such things as templates that don't come from a package. The RStudio UI only shows you templates that are provided by R packages as far as I can tell. Do you know of a case where that's not true? – MrFlick Mar 10 '22 at 17:36
  • @MrFlick - Please see edits above. – Karl Wolfschtagg Mar 10 '22 at 17:55
  • 4
    Your method basically hacks the existing `rmarkdown` package. Anything you add there will get wiped out when you update your `rmarkdown` package version. It's generally not a good idea to attempt to directly edit code inside an installed pacakge. It's much easier and safer just to create your own package which has the templates you want. – MrFlick Mar 10 '22 at 18:00
  • @MrFlick - Understood. I will learn to create my own package. Thank you! – Karl Wolfschtagg Mar 10 '22 at 18:30

0 Answers0