├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R └── use_quarto_ext.R ├── README.md ├── inst └── extdata │ └── _extensions │ └── quartotemplate │ ├── _extension.yml │ ├── fonts │ ├── Georgia Bold Italic.ttf │ ├── Georgia Bold.ttf │ ├── Georgia Italic.ttf │ ├── Georgia.ttf │ ├── Verdana Bold Italic.ttf │ ├── Verdana Bold.ttf │ ├── Verdana Italic.ttf │ └── Verdana.ttf │ ├── header.tex │ ├── img │ └── logo.png │ ├── logo.png │ └── template.qmd ├── man ├── hello.Rd └── use_quarto_ext.Rd └── quartotemplate.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | *.DS_Store 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: quartotemplate 2 | Type: Package 3 | Title: Example package showing how to include Quarto templates with R packages 4 | Version: 0.1.0 5 | Author: Spencer Schien 6 | Maintainer: Spencer Schien 7 | Description: This package serves as a minimal example for how to include Quarto templates with extension in R packages in the same manner as R Markdown templates. 8 | License: MIT + file LICENSE 9 | Encoding: UTF-8 10 | LazyData: true 11 | RoxygenNote: 7.2.1 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2022 2 | COPYRIGHT HOLDER: quartotemplate authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 quartotemplate authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(use_quarto_ext) 4 | -------------------------------------------------------------------------------- /R/use_quarto_ext.R: -------------------------------------------------------------------------------- 1 | #' Install bundled Quarto extensions into current working directory and create 2 | #' new qmd using skeleton documents. This function extends a function written by 3 | #' Thomas Mock: https://github.com/jthomasmock/octavo/blob/master/R/use_quarto_ext.R 4 | #' 5 | #' @param file_name Name of new qmd file and sub-directory to be created 6 | #' @param ext_name String indicating which extension to install 7 | #' 8 | #' @return a message if extension was successfully copied over 9 | #' @export 10 | use_quarto_ext <- function(file_name = NULL, 11 | ext_name = "quartotemplate") { 12 | 13 | if (is.null(file_name)) { 14 | stop("You must provide a valid file_name") 15 | } 16 | 17 | out_dir <- file_name 18 | 19 | if(!dir.exists(out_dir)) { 20 | dir.create(out_dir) 21 | } 22 | 23 | # check for available extensions 24 | stopifnot("Extension not in package" = ext_name %in% c("quartotemplate")) 25 | 26 | # check for existing _extensions directory 27 | if(!file.exists("_extensions")) dir.create("_extensions") 28 | message("Created '_extensions' folder") 29 | 30 | # various reading of key-value pairs for reporting 31 | ext_yml <- readLines(system.file("extdata/_extensions/quartotemplate/_extension.yml", 32 | package = "quartotemplate")) 33 | 34 | ext_ver <- gsub( 35 | x = ext_yml[grepl(x = ext_yml, pattern = "version:")], 36 | pattern = "version: ", 37 | replacement = "" 38 | ) 39 | 40 | ext_nm <- gsub( 41 | x = ext_yml[grepl(x = ext_yml, pattern = "title:")], 42 | pattern = "title: ", 43 | replacement = "" 44 | ) 45 | 46 | # Create folder for recursive copying into ahead of time 47 | if(!file.exists(paste0("_extensions/", ext_name))) dir.create(paste0("_extensions/", ext_name)) 48 | 49 | # copy from internals 50 | file.copy( 51 | from = system.file(paste0("extdata/_extensions/", ext_name), package = "quartotemplate"), 52 | to = paste0("_extensions/"), 53 | overwrite = TRUE, 54 | recursive = TRUE, 55 | copy.mode = TRUE 56 | ) 57 | 58 | # logic check to make sure extension files were moved 59 | n_files <- length(dir(paste0("_extensions/", ext_name))) 60 | 61 | if(n_files >= 2){ 62 | message(paste(ext_nm, "v", ext_ver, "was installed to _extensions folder in current working directory.")) 63 | } else { 64 | message("Extension appears not to have been created") 65 | } 66 | 67 | # create new qmd report based on skeleton 68 | readLines("_extensions/quartotemplate/template.qmd") |> 69 | writeLines(text = _, 70 | con = paste0(out_dir, "/", file_name, ".qmd", collapse = "")) 71 | 72 | # open the new file in the editor 73 | file.edit(paste0(out_dir, "/", file_name, ".qmd", collapse = "")) 74 | 75 | # copy header.tex over as well 76 | readLines("_extensions/quartotemplate/header.tex") |> 77 | writeLines(text = _, con = paste0(out_dir, "/header.tex")) 78 | 79 | } 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This package is meant to serve as a example for how to include Quarto templates with extensions in a fashion that reproduces the functionality of R Markdown templates included with R packages. The example included here could serve as a branded PDF report template. 4 | 5 | Specifically, the following functionality: 6 | 7 | * All template resources are included with the extension 8 | * Create a new Quarto document based on a template in a single function 9 | - A template skeleton is used as a template when creating a new Quarto document 10 | - Resources such as latex templates/headers are copied over 11 | - A sub-directory is created for the new report 12 | 13 | # Use 14 | 15 | Install this package with the following code: 16 | 17 | ``` 18 | remotes::install_github("Pecners/quartotemplate") 19 | ``` 20 | 21 | The `use_quarto_ext()` function will implement the functionality listed above. For example, executing `use_quarto_ext(file_name = "test")` will create a new director called `test` with a `header.tex` file and `test.qmd` file for the the new report. `test.qmd` is based on `skeleton.qmd` found [here](./inst/extdata/_extensions/quartotemplate/skeleton.qmd): `inst` > `extdata` > `_extensions` > `quartotemplate` > `skeleton.qmd` 22 | 23 | # Credits 24 | 25 | [Thomas Mock](https://twitter.com/thomas_mock) provided tips on Twitter that gave me the idea for this solution, and the `use_quarto_ext()` is an extension of a function he wrote in this repo: https://github.com/jthomasmock/octavo. 26 | -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/_extension.yml: -------------------------------------------------------------------------------- 1 | title: Quarto Template 2 | author: Spencer Schien 3 | version: 0.0.1 4 | -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Georgia Bold Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Georgia Bold Italic.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Georgia Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Georgia Bold.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Georgia Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Georgia Italic.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Georgia.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Georgia.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Verdana Bold Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Verdana Bold Italic.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Verdana Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Verdana Bold.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Verdana Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Verdana Italic.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/fonts/Verdana.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/fonts/Verdana.ttf -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/header.tex: -------------------------------------------------------------------------------- 1 | \usepackage{titling} 2 | \pretitle{ 3 | \begin{center} 4 | \huge 5 | \setmainfont{Georgia} 6 | \includegraphics[width=4cm,height=6cm]{../_extensions/quartotemplate/img/logo.png}\\[\bigskipamount] 7 | } 8 | \posttitle{\end{center}} 9 | \posttitle{\end{center}} 10 | \usepackage{booktabs} 11 | \usepackage{longtable} 12 | \usepackage{array} 13 | \usepackage{multirow} 14 | \usepackage{wrapfig} 15 | \usepackage{float} 16 | \usepackage{colortbl} 17 | \usepackage{pdflscape} 18 | \usepackage{tabu} 19 | \usepackage{threeparttable} 20 | \usepackage{xcolor} 21 | \usepackage{soul} 22 | \usepackage{graphicx} 23 | \usepackage{fancyhdr} 24 | \pagestyle{fancy} 25 | \rhead{\includegraphics[width = .05\textwidth]{../_extensions/quartotemplate/img/logo.png}} 26 | -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/img/logo.png -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pecners/quartotemplate/b186f252fde120fe352dc361dda6f58084d02a60/inst/extdata/_extensions/quartotemplate/logo.png -------------------------------------------------------------------------------- /inst/extdata/_extensions/quartotemplate/template.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Your Title" 3 | author: "Your Name" 4 | date: "Report Last Run: `r Sys.time()`" 5 | mainfont: Verdana 6 | sansfont: Georgia 7 | format: 8 | pdf: 9 | include-in-header: 10 | - header.tex 11 | --- 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE) 14 | library(tidyverse) 15 | library(knitr) 16 | library(kableExtra) 17 | library(RColorBrewer) 18 | library(scales) 19 | ``` 20 | 21 | ## Quarto 22 | 23 | Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see . 24 | 25 | ## Running Code 26 | 27 | When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: 28 | 29 | ```{r} 30 | 1 + 1 31 | ``` 32 | 33 | \newpage 34 | You can add options to executable code like this 35 | 36 | ```{r} 37 | #| echo: false 38 | 2 * 2 39 | ``` 40 | 41 | The `echo: false` option disables the printing of code (only output is displayed). 42 | -------------------------------------------------------------------------------- /man/hello.Rd: -------------------------------------------------------------------------------- 1 | \name{hello} 2 | \alias{hello} 3 | \title{Hello, World!} 4 | \usage{ 5 | hello() 6 | } 7 | \description{ 8 | Prints 'Hello, world!'. 9 | } 10 | \examples{ 11 | hello() 12 | } 13 | -------------------------------------------------------------------------------- /man/use_quarto_ext.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_quarto_ext.R 3 | \name{use_quarto_ext} 4 | \alias{use_quarto_ext} 5 | \title{Install bundled Quarto extensions into current working directory and create 6 | new qmd using skeleton documents. This function extends a function written by 7 | Thomas Mock: https://github.com/jthomasmock/octavo/blob/master/R/use_quarto_ext.R} 8 | \usage{ 9 | use_quarto_ext(file_name = NULL, ext_name = "quartotemplate") 10 | } 11 | \arguments{ 12 | \item{file_name}{Name of new qmd file and sub-directory to be created} 13 | 14 | \item{ext_name}{String indicating which extension to install} 15 | } 16 | \value{ 17 | a message if extension was successfully copied over 18 | } 19 | \description{ 20 | Install bundled Quarto extensions into current working directory and create 21 | new qmd using skeleton documents. This function extends a function written by 22 | Thomas Mock: https://github.com/jthomasmock/octavo/blob/master/R/use_quarto_ext.R 23 | } 24 | -------------------------------------------------------------------------------- /quartotemplate.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | --------------------------------------------------------------------------------