Specify custom powerpoint theme in R markdown - r

I am using R markdown to create a presentation. Here's a sample code:
---
title: "Untitled"
author: "April 2018"
date: "4/9/2019"
output: powerpoint_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Slide with Plot
```{r pressure, fig.width=30, fig.asp=0.618,
out.width="200%"}
plot(pressure)
```
I want to apply a custom template that is specified by my organisation. How do I specify the custom theme? I read online that this can be specified by:
---
title: "Untitled"
author: "April 2018"
date: "4/9/2019"
output: powerpoint_presentation:
reference_doc: my_theme.pptx
---
But how does this work? Where do I have to store the my_theme.pptx file?

I hope you don't need this answer now, but just in reference for all of the guyz who were seeking for the answer like me.
Go to >> R\win-library\version e.g. 4.0\officer >>> paste your custom template on this path.
It will work

Related

Rmarkdown Beamer presentation, option clash clash for xcolor

I am trying to build a beamer presentation using rmarkdown. In my presentation I want to include tables using the kable, and kableExtra packages. I am having issues with this because one of the LaTex packages that kableExtra requires is already loaded by the beamer presentation with different options. This is the error message that I receive.
! LaTeX Error: Option clash for package xcolor.
I have been searching for a fix for this but have not had any luck. I have found solutions on the LaTex pages, here and here, but I do not know LaTex and I have not figured out how to apply these solutions in the rmarkdown arena. I have tried looking at the Latex templates in rmarkdown, but I do not understand it well enough to try and implement these solutions.
Any thoughts or solutions would be much appreciated. Here is just a quick sample of the .Rmd that gives the error.
---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage[table]{xcolor}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:6]
```
## Slide with R Output
```{r cars, echo = TRUE}
kable(dt, format = "latex")
```
## Slide with Plot
```{r pressure}
plot(pressure)
```
The linked answer on the TeX stackexchange suggests adding table to the class options for the document e.g. \documentclass[a4paper,table]{article}. In order to do this in RMarkdown, you can use a classoption: line in your YAML header:
---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
classoption: table
output:
beamer_presentation:
keep_tex: true
---

Passing parameters in rmarkdown to the text or headings

Is there any way to pass parameters in an rmarkdown document outside of a code chunk? For example, I'd love to have the ability to have a parameter value be a heading.
Here is a short example .Rmd file:
---
title: "param_test"
author: "test"
date: "September 14, 2017"
output: pdf_document
params:
param_test: this_text
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## I want this heading to be the value of params$param_test
```{r cars}
params$param_test
print(params$param_test)
```
Does anyone have any ideas on this?
You just need to add results='asis' to the chunk then you can print out the header from within the code.
cat("#", params$param_test, "\n")
Another option would be to use the pander library and run
pandoc.header(params$param_test)

How to remove compact title from R markdown to latex conversion?

I wrote my own titlepage and it is loaded via an include in the R-markdown file. However, this conflicts with the pandoc title. I am trying to find settings in the R markdown yaml header such that pandoc does not insert the following code snipped into the tex-file.
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{}
\pretitle{\vspace{\droptitle}}
\posttitle{}
\author{}
\preauthor{}\postauthor{}
\date{}
\predate{}\postdate{}
There is no clear indication in the pandoc documents or the r markdown guidelines how to disable the title generation. Any help would be appreciated.
Update: In particular, I am looking for solutions that allow me to keep creating my title page with the \maketitle command. That is why I focussed on this particular code snipped that I want to get rid of.
I also use my own title page with rmarkdown documents for latex/pdf outputs. To remove the title, you can add the following command in a text file called with in_header :
\AtBeginDocument{\let\maketitle\relax}
A reproductible example with the header.tex file built directly within the Rmd document:
---
title: "RMarkdown No title Test"
author: "StatnMap"
date: "July 30, 2017"
output:
pdf_document:
includes:
in_header: header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r rm_title_page, echo=FALSE}
head <- cat('
\\AtBeginDocument{\\let\\maketitle\\relax}
', file = "header.tex")
```
# Title 1
**Some text**
# Title 2
**Some text**
Using compact-title: false in the YAML works.
---
title: "This title is not compact"
author: "Test"
date: "2019 May 10"
output: pdf_document
compact-title: false
---
I had the same problem today. Here's what I did. (Maybe I'll update the solution when I come up with something better.)
The solution is dumb but useful. I can't set an arbitrary space between the lines now, because I used \newline.
---
title: "\\huge My Smart Title"
author: "\\newline \\Large My Smart Author"
date: "\\newline \\Large 2018-12-25"
output:
pdf_document:
includes:
in_header: preamble.tex
latex_engine: xelatex
---
Below are the outputs before and after the solution.
BEFORE:
AFTER:
Note:
You may be confused about the different sizes of the "author" and the "date" in the two pictures above, if you don't know that the fontsize of the "author" and the "date" is \large instead of \Large by default.
END

How to suppress automatic figure numbering in Rmarkdown / pandoc

I have the following Rmarkdown (.Rmd) document where I call existing .png images and create a .pdf with captions. By default, pandoc? is automatically adding "Figure #." before the caption for each picture. I can see how this would be the normal thing to do, but in my case I would like to define this. I have found variations on this topic but don't seem to find a solution. Below is an example of how my .Rmd file looks:
---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output:
pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
![Caption for figure 1](figures/plot1.png)
\newpage
![Caption for figure 2](figures/plot2.png)
You could use the caption-package
Create a .tex-file that you specify the following in, this below remove the entire label and you are free to hardcode the labels.
\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
Then your .rmd should look like this:
---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output:
pdf_document:
includes:
in_header: YourName.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
![Caption for figure 1](figures/plot1.png)
\newpage
![Caption for figure 2](figures/plot2.png)
Simplified: As suggested in the comments, we can achieve this within our .Rmd file, as shown below.
---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output:
pdf_document:
header-includes:
- \usepackage{caption}
- \captionsetup[figure]{labelformat=empty}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
![Caption for figure 1](figures/plot1.png)
\newpage
![Caption for figure 2](figures/plot2.png)

output markdown in r code chunk

I have a R markdown file that I want to output rmarkdown from the script itself. For example, I would have the following simple code in an Rmd file.
---
title: "test"
author: "johndoe"
date: "September 5, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars}
paste("## This is a Heading in Code")
summary(cars)
```
I want "This is a Heading in Code" to render in rmarkdown. There is a solution in an R script to generate markdown as per http://rmarkdown.rstudio.com/r_notebook_format.html. But I am trying to figure out how to do this in a Rmarkdown file. Any help appreciated. Thanks.
Why build the header markup (either in markdown or HTML) manually? Try inline R expressions or some helper functions in pander (to generate markdown programatically):
---
title: "test"
author: "johndoe"
date: "September 5, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## `r 'This is a Heading in Code'`
```{r title, results='asis'}
library(pander)
pandoc.header("This is a Heading in Code", level = 2)
```
```{r cars, results='asis'}
summary(cars)
```
I searched for a good answer for this for some time after using cat("## Heading") inside results='asis' code chucks. I have seen many people dissatisfied by the results='asis' setting in the code chunk because it sets all results of the code chunk to not be wrapped in a code markup block. We have many cases when we want to output the heading along with results that should be wrapped in markup (e.g. a kable table that renders to a html table).
Here is the solution I found by simply specifying the "asis" attribute to the text object with knitr::asis_output and keeping the code chunk in the default 'markup' setting.
---
title: "test"
author: "johndoe"
date: "September 5, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars}
knitr::asis_output("## This is a Heading in Code")
summary(cars)
knitr::kable(summary(cars))
```
Unfortunately, at the current time knitr::asis_output only works in top-level R expressions, and it will not work when it is called inside another expression, such as a for-loop.

Resources