#' Prints out preferred HTML formatting for RMarkdown documents
#'
#' Prints out preferred HTML formatting for RMarkdown documents. Will print YAML, CSS styling, global chunk options, and common packages. Currently not customizable via the function. Purpose is to print out
#' text to copy/paste into new RMarkdown documents for quick access to favorite style.
#' This is a preferred alternative to Rmarkdown templates as customizable features may be included in the future.
#' @param os Operating system - either "PC" or "mac." Will adjust CSS according to operating system.
#' @export
get_fmt <- function(os = "PC"){
if(os != "PC" & os != "mac") stop("os must be one of PC or mac")
cat(sep = "\n",
"---",
"title: \" \"",
"author: Molly A. Olson, MS",
"date: \"Updated: `r format(Sys.time(), '%d %B, %Y')`\"",
"output:",
" html_document:",
" toc: yes",
" toc_depth: 5",
" toc_float:",
" collapsed: yes",
" number_sections: true",
"---",
"",
"",
"<style type=\"text/css\">",
"#TOC{",
"position:fixed;",
"top:0;",
"right:0;",
"margin: 40px 40px 40px 40px;",
"background-color: #F0F0F0;",
"border-color: DarkBlue;",
"z-index: 9;",
"}",
"#toc-toggle{",
"position:fixed;",
"top:0;",
"right:0;",
"margin: 5px 20px 5px 20px;",
"}")
if(os == "mac"){
cat(".col-lg-3 {\n")
} else {
cat(".col-md-3 {\n")
}
cat(sep = "\n",
" width: 3%;",
"}",
"div.container-fluid.main-container{",
" max-width: none;",
" margin-left: none;",
" margin-right: none;",
"}",
"p img{",
" max-width:none;",
"}",
".title{",
" max-width:100ex;",
"}",
"h1.title {",
" font-size: 30px;",
" color: DarkBlue;",
"}",
"h1 { /* Header 1 */",
" font-size: 26px;",
" color: DarkBlue;",
"}",
"h2 { /* Header 2 */",
" font-size: 22px;",
" color: DarkBlue;",
"}",
"h3 { /* Header 3 */",
" font-size: 18px;",
" color: DarkBlue;",
"}",
"h4 { /* Header 4 */",
" font-size: 16px;",
" color: DarkBlue;",
"}",
"h5 { /* Header 5 */",
" font-size: 16px;",
" color: DarkBlue;",
"}",
"hr {",
" border-color: DarkBlue;",
" width:100%;",
" border-width:2px;",
"}",
"</style>",
"",
"<button id=\"toc-toggle\" type=\"button\" class=\"btn btn-default btn-xs code-folding-btn pull-right collapsed\" onclick=\"toggletoc()\"><span>Table of Contents</span></button>",
"",
"<script>",
"function toggletoc(){",
"$(\"#TOC\").toggle();",
"}",
"</script>",
"",
"<hr>",
"",
"",
"```{r, include = FALSE}",
"# set echo to TRUE if want to include code-folding",
"knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, collapse = TRUE, fig.align = 'center')",
"knitr::opts_chunk$set(error = FALSE)",
"```",
"",
"```{r, packages}",
"library(tidyverse)",
"library(Hmisc)",
"library(rms)",
"library(kableExtra)",
"library(knitr)",
"library(tableone)",
"library(here)",
"library(mollR)",
"```"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.