You have created an RStudio template (for an R Markdown file, see Chapter 17 Document Templates | R Markdown: The Definitive Guide), this is not the same as a new output format which is specified in the YAML front-matter as output: mypkg::my_cool_format. Output formats are exported R functions that return an object with the class "rmarkdown_output_format".
If your RStudio template is working correctly, you should be able to open RStudio and then go to File > New File > R Markdown... > From Template, and then find your template and choose "OK". This should open your R Markdown template and you should be good.
Since you have so much custom configuration in your YAML front matter of amaRyaml/skeleton.Rmd at master · Amarakon55/amaRyaml · GitHub you may consider actually creating a new output format that hides these technical details inside a custom TeX template.
Hello. I don't use the RStudio IDE, I actually edit my files in VIM. So I basically can't use RStudio to use my template. I want to explore the second option of creating a new output format. I looked at this:
It says to write a function and provides an example with a code block. However, I'm not sure on which file should I put that code for the function.
Within your R package and within the R sub-directory, you should create a script that contains an R function for your new output format. I think it makes sense to build your custom format on top of bookdown::pdf_document2() since you use this in your YAML frontmatter. So you will create your own function that modifies this base format in various ways to achieve your desired specification.
# amaRyaml/R/pdf_custom.R
#' My Custom Format
#'
#' @param ...
#'
#' @export
# Accept whatever configurable arguments you want...
pdf_custom <- function() {
# Set up other custom format options...
# Define the base format you will build upon
base <- bookdown::pdf_document2(
number_sections = TRUE,
toc_depth = 3,
latex_engine = 'xelatex',
# pass in whatever other arguments you want...
)
base
}
Those that are only skeleton Rmd files with contains default configuration and some resources to use with it, and that will use any existing rmarkdown format. The skeleton will usually contain some YAML configuration and use asoutput_format an existing R function for a package. A lot of things can be customize this way already.
Template that requires a custom format. Usually, this is required when some advanced processing are needed (pre-processor / post-processor), or to simplify the usage of the template as the custom format will be able to set different default value for an existing format without the user having to specify those values in YAML.
Often when 2. is done, there is also a template of type 1. to show how it works.
Regarding distribution, in case 1. this could live in a repo to clone / download or in R Package. For case 2, it needs to be in a R package so that it can be called during rendered
output: mycustom::format
I don't know exactly which one suits you best. It seems from your repository that the type 1. is ok. You have a skeleton and some resources, you could bundle that in a package and if you don't use RStudio, the function rmarkdown::draft() will allow to create new document based on that template . 16.8 R Markdown templates in R packages | R Markdown Cookbook
I have the inst directory which has the necessary files including skeleton.Rmd. Also I wasn't sure if I should have set create_dir to true or false but I went with true.
I also have an R directory that defines the functions. Here is an example document:
---
title: Example
output: amaRyaml::eisvogel
---
Lorem ipsum.
It actually works, but I just have one problem: It's not reading the skeleton.Rmd file! The eisvogel function works, but this specific part in eisvogel.R is not working for some reason:
Your example document does not look like your template skeleton.Rmd. You may not have correctly understood how template works. They are Rmd document stored in a package that could be retrieved as template (model / example) to build on too for creating a new Rmd document.
A skeleton.Rmd won't be used in the process of rendering another Rmd document. Maybe a template is not what you need for what you want to do. Possibly a custom output format is enough to set some knitr option, and pass some Pandoc variable that you may need.
With a skeleton, user of your package will be able to retrieve the included document easily so that they can have the YAML and some content already there as template in the new Rmd they will be creating.
rmarkdown::draft() is used to create a new document by a user based on a template. I don't see the equivalent function in your R code. But I may have missed it. Which function is that ?
The template won't be read by your function. As I am saying above, it is stored inside the package so that a use can easily create a new document based on that.
Have you look at the doc ? We can clarify things if this is not. Some more resources if you do not have found it yet
It seems you are missing some quotes to pass string to rmarkdown::draft arguments. You are passing R variable name currently, and those objects are not defined. Hence object not found.
Yes, it says "object amaRyaml not found". I also tried with the rticles package. Still the same issue. rmarkdown::draft() is not working even though I am providing it with all the information it needs according to this. This has to be a problem with the rmarkdown package itself or something on my end.
This error is generally thrown when you used amaRyaml instead of "amaRyaml". I explained that above. Did you really retried adding the quotes " around ?
# create temp dir
dir.create(tmp_dir <- tempfile())
# Empty
list.files(tmp_dir)
#> character(0)
# install your package
remotes::install_github("Amarakon55/amaRyaml")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'amaRyaml' from a github remote, the SHA1 (85894f69) has not changed since last install.
#> Use `force = TRUE` to force installation
# create a template
xfun::in_dir(tmp_dir, {
rmarkdown::draft("file.Rmd", template = "eisvogel", package = "amaRyaml", edit = FALSE)
})
# It is there
list.files(tmp_dir, recursive = TRUE)
#> [1] "file.Rmd"
#> [2] "fonts/LiberationSerif-Bold.ttf"
#> [3] "fonts/LiberationSerif-BoldItalic.ttf"
#> [4] "fonts/LiberationSerif-Italic.ttf"
#> [5] "fonts/LiberationSerif-Regular.ttf"
# clean example
unlink(tmp_dir, recursive = TRUE)
When I copied and pasted rmarkdown::draft("file.Rmd", template = "eisvogel", package = "amaRyaml", edit = FALSE), it actually worked. Don't know why it didn't work before. Maybe I forgot to wrap something in quotes. Thanks so much for helping me.