I would like to use R Markdown to produce a document that takes advantage of certain LaTeX packages. Sometimes, I want to render the Rmd document to PDF. At other times, I want to render it to HTML.
I would like to load packages via the extra_dependencies option, rather than through the includes or header-includes options. Some of the LaTeX packages should be loaded with options. Others shouldn't be.
When I render the Rmd document to PDF, there is no problem. But when I try to render the same document to HTML, rmarkdown::render chokes on the processing of the extra_dependencies argument. (I am using rmarkdown 2.1.) Here is a minimal example, following the style of the R Markdown Cookbook:
---
title: "Test Processing of YAML Header in R Markdown Document"
output:
html_document:
extra_dependencies:
array: null
numprint: ["autolanguage"]
---
Hello.
Rendering that document with rmarkdown::render generates a dependency_resolver -> <Anonymous> -> sapply -> lapply error. If I add dashes before array and numprint, the error is instead Error: invalid version specification 'NULL'. But if I just change html_document to pdf_document, there is no problem.
How may I generate an HTML document while loading packages through the extra_dependencies option? And why does this example work when I generate PDF documents, but not when I generate HTML documents?