title: Change background in R Markdown beamer presentation
body: <p>I'm writing on a beamer presentation in rmarkdown and I have two types of frames which should differ by their background.
  So I wrote two functions like that in latex:</p>
  
  <pre><code>\newcommand{\settitlestyle}{
  \setbeamertemplate{background canvas}{%
    \includegraphics[width = \paperwidth, height = \paperheight] 
  {backgroundtitle.jpg}}
  } 
  </code></pre>
  
  <p><code>\setmainstyle</code> is exactly the same command but another jpg.</p>
  
  <p>In the YAML I have already input a tex file that defines the functions and calls <code>\settitlestyle</code>. Works. But after the first slide I want to switch to the mainstyle. When I call <code>\setmainstyle</code> in the markdownfile nothing happens. </p>