What is too constraining about the YAML approach? You can include
arbitrary content in the HTML header via the includes option if you
save the content in a file.
knitr::opts_knit$set( header=X) only works for Rnw and Rhtml
documents. It does not apply to R Markdown.
Regards,
Yihui