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)
```
Related
I have the following code chunks in R markdown that produce 2 plots with some text in between but the pdf output is just sending all plots to the bottom of the document. How can I make it so the Plot stays in the spot of the text where I want it to be?
---
title: "Evaluation of Income annuities with money-back guarantees"
author: "Long Life Insurance Company's Actuarial Team"
output:
word_document:
toc: yes
pdf_document:
fig_width: 6
fig_height: 3.5
fig_caption: yes
fig_crop: no
toc: yes
number_sections: yes
---
[Text]
{r, echo=FALSE, include=TRUE, messages=FALSE, warnings=FALSE, fig.cap = "EPVs at different ages and interest rates"}
plot(xAges,EPVs[1,],ylim=c(min(EPVs),max(EPVs)),main="EPV of CRIA",xlab=
"Annuitant's age",ylab="EPV",pch=1,cex=0.5,col=2)
legend(60,30, legend=c("r = 2%", "r = 4%","r = 6%", "r = 8%"),col=2:5, pch=c(1,3,8,16), cex=1)
[Text]
{r, echo=FALSE, messages=FALSE, warnings=FALSE,fig.cap = "EPVs at different given interest rates"}
plot(IntRates65,EPVs[1,],ylim=c(min(EPVs),max(EPVs)),main="EPV of all 3 products",xlab=
"Interest rate",ylab="EPV",pch=1,cex=0.8,col=2)
legend(0.08, 16, legend=c("LOIA", "IRIA","CRIA"),col=2:4, pch=c(1,3,8), cex=0.8)
[Text]
Tried code above but it sends all plots to the bottom
I think that simply putting each figure in its own chunk with ``` in the beginning and end, will do the trick, like so
---
title: "Evaluation of Income annuities with money-back guarantees"
author: "Long Life Insurance Company's Actuarial Team"
output:
word_document:
toc: yes
pdf_document:
fig_width: 6
fig_height: 3.5
fig_caption: yes
fig_crop: no
toc: yes
number_sections: yes
---
[Text]
```{r, echo=FALSE, include=TRUE, messages=FALSE, warnings=FALSE, fig.cap = "EPVs at different ages and interest rates"}
barplot(c(2,5))
```
[Text]
```{r, echo=FALSE, messages=FALSE, warnings=FALSE,fig.cap = "EPVs at different given interest rates"}
barplot(c(2,5), main="Main title",
xlab="X axis title",
ylab="Y axis title",
sub="Sub-title")
```
[Text]
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:
I am working in a book, using R and the Tufte library.
I am using the following YAML for each .Rmd Chapter:
---
title: "Chapter 2: A First Linear Program"
header-includes:
\usepackage{longtable}
\usepackage{caption}
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
And the following one is the YAML for the index .Rmd file:
---
title: "Operations Research Using R<br />"
author: "Timothy R. Anderson"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: ["Master4Bookdowns.bib"]
---
# Preface {-}
I have tried different options like adding the sansfont and mainfont in YAML:
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
sansfont: Calibri Light
mainfont: Calibri Light
But it didn't change the font inside the chunk, only the text outside.
Here a simpler example document showing my attempt to change monofont as suggested in the comments:
---
title: "Chapter 2: A First Linear Program"
header-includes:
\usepackage{longtable}
\usepackage{caption}
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
monofont: Times New Roman
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).
```{r base_case_no_pipes_step_4}
model0d <- c("example", 6 + 2 <= 2000)
#fabrication
model0e <- c("example", 8 + 6 <= 2000)
#assembly
```
You have to bring the YAML headers to the right level:
monofont et al. are top-level headers
highlight is below the output format, not below output
The following example uses "Times New Roman" for the code block and XeLaTeX's default font (Latin Modern) for the main text. You can change that with mainfont. In addition, there is no syntax highlighting:
---
title: "Chapter 2: A First Linear Program"
header-includes:
- \usepackage{longtable}
- \usepackage{caption}
monofont: Times New Roman
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).
```{r base_case_no_pipes_step_4}
model0d <- c("example", 6 + 2 <= 2000)
#fabrication
model0e <- c("example", 8 + 6 <= 2000)
#assembly
```
Result:
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
---
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
---