Inline R code in YAML for rmarkdown doesn't run

后端 未结 2 717
时光说笑
时光说笑 2020-12-19 07:36

I\'m trying to run inline R code in the YAML front matter before getting rmarkdown to run the file. However it isn\'t working for me. Here\'s an example:

2条回答
  •  遥遥无期
    2020-12-19 08:27

    So I found a round about way of getting what I wanted. Rmarkdown I don't think allows R expressions/commands in the YAML, probably for a good reason. What I ended up doing was putting all the output yaml commands in a file called _output.Ryaml like so:

    beamer_presentation:
      slide_level: 2
      includes:
        in_header: "src/preamble.tex"
      pandoc_args: [
        "--bibliography", "`r paste('path/to/bib')`",
        "--variable", "classoption:xcolor=dvipsnames",
        "--variable", "fontsize:9pt"
        ]
    

    Then in the main slides.Rmd file, was something like:

    ---
    title: "**Title**"
    author: Luke
    ---
    
    
    ## Intro ##
    

    Then, I can generate the slides using the R code (which I put into a Makefile):

    knitr::knit('_output.Ryaml', '_output.yaml')
    rmarkdown::render('slides.Rmd')
    unlink('_output.yaml')
    

    Seems to be working well enough. If anyone's got a better idea, let me know!

提交回复
热议问题