title: Can I set the CSS/JS paths parametrically in Xaringan YAML?
body: <p>This is similar to <a href="https://github.com/yihui/xaringan/issues/29" rel="nofollow noreferrer">Xaringan issue #29</a>. I'm setting up a Xaringan template to be used at work, and I want to keep all the CSS and Javascript files in the same location. I don't want anyone to have to copy the same files into each presentation directory.</p>
  
  <p><em>However</em>, I also don't want to refer to a common root directory. I <em>could</em> (I think) point to our in-house Bitbucket server, but I would much rather analysts and data scientists be able to get the files from their local repo (for speed, and also in case they're not on the network or are making their own changes).</p>
  
  <p>I'm also not particularly hung up on using Infinite Moon Reader. (That was part of issue #29.) It's easy enough for me to remember to hit <code>Control+Shift+K</code> every time I hit <code>Control+S</code>.</p>
  
  <p>What I had in mind was just to include a <code>xaringan_dir</code> parameter, and use that in my lists of CSS / JS resources.</p>
  
  <p>My file structure at the moment is my <code>xaringan</code> directory, in which I have a <code>css</code> directory for CSS, a <code>js</code> directory for Javascript, and <code>company-xaringan-template.Rmd</code>. <em>This</em> YAML works:</p>
  
  <pre><code>---
  title: 'This is a Title'
  subtitle: 'This is a subtitle'
  author: 'Benjamin Wolfe'
  date: 'January 1, 2019 (revised `r Sys.Date()`)'
  output:
    xaringan::moon_reader:
      css: [default, ./css/company-theme.css, ./css/company-theme-fonts.css, ./css/custom-classes.css]
      lib_dir: libs
      nature:
        beforeInit: './js/macros.js'
        highlightStyle: github
        highlightLines: true
        countIncrementalSlides: false
        slideNumberFormat: '%current%'
        ratio: '16:9'
  ---
  </code></pre>
  
  <p>To parametrize my YAML, I tried this:</p>
  
  <pre><code>---
  title: 'This is a Title'
  subtitle: 'This is a subtitle'
  author: 'Benjamin Wolfe'
  date: 'January 1, 2019 (revised `r Sys.Date()`)'
  params:
    xaringan_dir: '.'
  output:
    xaringan::moon_reader:
      css: [`r paste(c('default', file.path(params$xaringan_dir, 'css', c('company-theme.css', 'company-theme-fonts.css', 'custom-classes.css'))), collapse = ', ')`]
      lib_dir: libs
      nature:
        beforeInit: '`r file.path(params$xaringan_dir, "js", "macros.js")`'
        highlightStyle: github
        highlightLines: true
        countIncrementalSlides: false
        slideNumberFormat: '%current%'
        ratio: '16:9'
  ---
  </code></pre>
  
  <p>I know I can use parameters in my YAML. This works, for example:</p>
  
  <pre><code>---
  title: 'This is a Title'
  author: 'Benjamin Wolfe'
  date: 'January 1, 2019 (revised `r Sys.Date()`)'
  params:
    xaringan_dir: '.'
    foo_bar: 'This is a subtitle'
  subtitle: '`r params$foo_bar`'
  output: ...
  ---
  </code></pre>
  
  <p>And my <code>r</code> snippets work by themselves. These lines work as expected:</p>
  
  <pre><code>params &lt;- list()
  params$xaringan_dir &lt;- '.'
  
  paste(c('default', file.path(params$xaringan_dir, 'css', c('esurance.css', 'esurance-fonts.css', 'custom-classes.css'))), collapse = ', ')
  file.path(params$xaringan_dir, "js", "macros.js")
  </code></pre>
  
  <p>But when I run my parametrized YAML, I get this error:</p>
  
  <pre><code>Error in yaml::yaml.load(..., eval.expr = TRUE) : 
    Scanner error: while scanning for the next token at line 9, column 11 found character that cannot start any token at line 9, column 11
  Calls: &lt;Anonymous&gt; ... parse_yaml_front_matter -&gt; yaml_load -&gt; &lt;Anonymous&gt;
  Execution halted
  </code></pre>
  
  <p>Additional notes:</p>
  
  <ul>
  <li>If I use my original, non-parameterized <code>beforeInit</code> line, with the new <code>css</code> line, I get the same error.</li>
  <li>If I use my original, non-parameterized <code>css</code> line, with the new <code>beforeInit</code> line, it knits the document but the document won't render in my browser.</li>
  </ul>
  
  <p>Any ideas? Can this be done? And/or should I be considering another approach?</p>