[Tex/LaTex] Adding background color to specific slide in beamer when using rmarkdown

beamercolorknitrmarkdown

I want to highlight an entire slide in a presentation I am creating in R markdown, much in the same way as was done in this answer (without using markdown).

Cannot seem to figure it out though. Below is a dummy example of my failure so far…

---
title: "Untitled"
output: beamer_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

% \setbeamercolor{background canvas}{bg=red}

## Slide with R Output 

\setbeamercolor{background canvas}{bg=red}

```{r cars, echo = TRUE}
summary(cars)
```

Best Answer

I created a key, bgcolor, that can be passed as an option to a frame. In the example below, only the second slide has a red background.

\documentclass{beamer}

\makeatletter
\define@key{beamerframe}{bgcolor}[]{%
  \ifx#1\@empty\else
    \def\ps@navigation@colored{%
      \setbeamercolor{background canvas}{bg=#1}%  background color
      \@nameuse{ps@navigation}}
    \thispagestyle{navigation@colored}
  \fi}
\makeatother


\begin{document}

\begin{frame}
  Test
\end{frame}


\begin{frame}[bgcolor=red]
  Test
\end{frame}


\begin{frame}
  Test
\end{frame}

\end{document}