italics in YAML title:

I'm attempting to set up a boilerplate report using parameters. One parameter is a species name, which I would like to have italicized in the report title. I can get the parameter into the title, but I've tried every combination of pasting "*", bquote(italics()), expression(italics()), and substitute(italics()) I can think of.
This works but doesn't italicize:

---
params:
TargetTaxon: "Peromyscus maniculatus"
UnitName: "Yosemite National Park"
title: |
| Species Occurrence Report for
| `r params$TargetTaxon\
| in `r params$UnitName\
author: "tp"
date: "\r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---

These have not worked:
| `r paste0('*', params$TargetTaxon, '*')`
| `r bquote(~italic(.(params$TargetTaxon)))`
| `r expression(italic(params$TargetTaxon))`
with or without the tilde ~ and .() wrapping.

Most combinations throw errors about

Error in vapply(x, format_sci_one, character(1L), ..., USE.NAMES = FALSE) :
values must be length 1,
but FUN(X[[2]]) result is length 2
Calls: ... paste -> hook -> .inline.hook -> format_sci -> vapply
Execution halted

| `r bquote(italic(.(params$TargetTaxon)))`

returns: "italic, Peromyscus maniculatus" as the second line of the title.

I suspect I could use explicit html or LaTeX tags for italics, but this Rmd will be rendered to both output formats.

Knitr should recognize the Markdown in the title without you having to paste it or add with R. This works for me:

---
params:
  TargetTaxon: "Peromyscus maniculatus"
  UnitName: "Yosemite National Park"
title: |
  | Species Occurrence Report for
  | *`r params$TargetTaxon`*
  | in `r params$UnitName`
author: "tp"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---
2 Likes

Thank you so much! That was a combination that didn't occur to me, but after thinking about the order in which R and markdown are rendered, it makes sense.
I kept banging my head on my desk because that did not italicize the species name in my production report. By adding & subtracting other parameters, I determined that theme:journal was the problem.

output:
html_document:
theme: journal
...

prevents the italics.

3 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.