Markdown YAML date settings using functions that require library() - r

I'd like to set date in YAML in R Markdown settings using following function:
paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")
but this code contains functions from 2 packages: timeperiodsR and lubridate, so it's necessary to prior use library(timeperiodsR) and library(lubridate).
How should code after date: look like, because the following is not working?
title: " "
date: '`r library(timeperiodsR) library(lubridate) paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'

Use ";" to indicate newline:
---
title: "mytitle"
date: '`r library(timeperiodsR); library(lubridate); paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'
---
Or use base (no dependencies, one-liner):
---
title: "mytitle"
date: '`r format(seq(Sys.Date(), length = 2, by = "-1 months")[ 2 ], format = "%B %Y")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'
---
Both give the below same output:

Related

Run shiny document with table of content

When I add the following lines to add table of content to a shiny document:
toc: true
toc_float: true
The document fails to run. It runs fine without them. I get the following error:
Error Scanner error: mapping values are not allowed in this context at line 5, column 8 (line 5 is toc: true)
How can I resolve this issue?
The code I ran:
---
title: "Untitled"
runtime: shiny
output:
html_document
toc: true
toc_float: true
---
### section 1
```{r, echo=FALSE}
sliderInput("slider", "Number of observations:", 1, 100, 50)
renderText({paste0(rep('blah', 100), collapse = '\n')})
```
### section 2
```{r, echo=FALSE}
renderPlot({hist(rnorm(500)[seq_len(input$slider)])})
```
You're just missing a : from html_document. It should be html_document:
---
title: "Untitled"
runtime: shiny
output:
html_document:
toc: true
toc_float: true
---

R markdown pdf, some output won't show

So I decided to convert my html R markdown file to a pdf knitr and I noticed that half my code output won't show. I replicated a small example here:
---
title: "Test"
author: "Brandon Morgan"
date: "1/19/2021"
output:
pdf_document:
df_print: paged
fig_caption: yes
fig_height: 6
fig_width: 7
highlight: tango
toc: yes
toc_depth: 4
html_document:
code_folding: hide
csl: biomed-central.csl
fig_caption: yes
fig_height: 6
number_sections: yes
theme: sandstone
toc: yes
toc_float: yes
---
# TEST
## Data
```{r}
data = iris
head(data)
```
Here's my html knitr output:
Here's my pdf knitr output:
Notice how head(data) does not show for pdf output
quick fix: remove df_print: paged. I can't tell you why it would not produce the result you want at the moment.
---
title: "Test"
author: "Brandon Morgan"
date: "1/19/2021"
output:
pdf_document:
fig_caption: yes
fig_height: 6
fig_width: 7
toc: yes
toc_depth: 4
html_document:
code_folding: hide
csl: biomed-central.csl
fig_caption: yes
fig_height: 6
number_sections: yes
theme: sandstone
toc: yes
toc_float: yes
---
# TEST
## Data
```{r echo=FALSE, results=TRUE}
data = iris
head(data)
```

Table of contents under a tab in R Markdown

I am trying to make an R Markdown doc with tabs and a table of contents under each tab
Here is my header:
---
title: "Palliative/Comfort Care/Hospice Patients Report"
output:
html_document:
toc: true
toc_floating: true
theme: "cerulean"
date: "`r format(Sys.time(), '%B %d, %Y')`"
pdf_document: default
---
Followed by:
# {.tabset}
## tab1
## tab 2

R Markdown index for titles

I have seen people that are able to create an index based on the titles that you have on your R markdown document like in this picture
If somebody could let me know how would I have to modify this code so it creates that left index table?
---
title: "Untitled"
author: "Juan Lozano"
date: "October 19, 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Title 1
Text Text Text Text Text
```{r cars}
summary(cars)
```
## Title 2
Text Text Text Text Text
As #hrbrmstr 's link indicates there are many YAML customisations possible:
This is the sort of thing I usually use:
---
title: "Untitled"
author: "john Smith"
date: "today ;)"
output:
html_notebook:
fig_caption: yes
number_sections: yes
toc: yes
toc_float: yes
html_document:
fig_caption: yes
number_sections: yes
toc: yes
toc_float: yes
df_print: paged
bibliography: /path/to/library.bib
---

Multiple authors in multiple lines in rmarkdown beamer presentations

I want to breakdown the authors' names into two lines in Rmarkdown beamer presentation. My YAML is as follows:
---
title: "***"
author:
- Author One
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 14pt
output:
beamer_presentation:
fig_height: 5
fig_width: 8
highlight: tango
theme: metropolis
incremental: true
---
But still, the authors' names printed on the same line. How can I break into two?
If you use the TeX command \newline after the first author this will render on a second line.
---
title: "***"
author:
- Author One\newline
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 14pt
output:
beamer_presentation:
fig_height: 5
fig_width: 8
highlight: tango
theme: metropolis
incremental: true
---

Resources