Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include an extra section of text/hyperlink in YAML-Header section of Rmarkdown document

Tags:

r

yaml

r-markdown

I'm writing a document in RMarkdown and have hopefully a fairly straightforward query about including extra information in the header section.

My Header section of the rmd looks like:

---
title: "My R-Markdown Document"

author: "[My name here](a hyperlink to my institutional page)"

output: html_document
---

I'm trying to add a simple extra line after my name which includes my Twitter handle

I tried cheating by adding it as an abstract....:

---
    title: "My R-Markdown Document"

    author: "[My name here](a hyperlink to my institutional page)"

    abstract: "[I'm on Twitter](hyperlink)"

    output: html_document
    ---

But that displays the heading Abstract before the extra information i.e I get

"Abstract: I'm on Twitter"

Whereas the desired output would be

Title Text

Name (Hyperlink)

I'm on Twitter (Hyperlink)

Anyone know how to get this to work? I've looked at PANDOC Guide and other examples and I've tried all sorts of things calling it description, institute but none of these seem to render except for Abstract which has the issue highlighted above.

NB: Modified-extra query This works for an HTML output but doesn't seem to if output == PDF Any suggestions in that realm also welcomed!

like image 616
mmarks Avatar asked Oct 23 '17 23:10

mmarks


People also ask

How do you hyperlink in R markdown?

Hyperlinks are created using the syntax [text](link) , e.g., [RStudio](https://www.rstudio.com) . The syntax for images is similar: just add an exclamation mark, e.g., ![ alt text or image title](path/to/image) . Footnotes are put inside the square brackets after a caret ^[] , e.g., ^[This is a footnote.] .

What is YAML header in R markdown?

YAML header is a short blob of text, specially formatted with key: value pairs tags, that seats at the top of our Rmarkdown document. The header not only dictates the final file format, but a style and feel for our final document.

How do you add a table of contents to a RMD?

You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` ### Header 3 Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. I tried running this in RStudio v 0.98.

How do I add a header in R markdown?

We can insert headings and subheadings in R Markdown using the pound sign # . There are six heading/subheading sizes in R Markdown. The number of pound signs before your line of text determines the heading size, 1 being the largest heading and 6 being the smallest.


1 Answers

There are a couple of ways to render the RMarkdown YAML header content for a single field on multiple lines. The following examples work for me in both pdf and html formats:

Using two spaces followed by \n

---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)  \n[I'm on Twitter](hyperlink)"
output:
  pdf_document: default
  html_document: default
---

Using the | operator

---
title: "My R-Markdown Document"
author: |
  | [My name here](a hyperlink to my institutional page)
  | [I'm on Twitter](hyperlink)
output:
  pdf_document: default
  html_document: default
---

Using html line break <br> (works for html, not pdf)

---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)<br><br>[I'm on Twitter](hyperlink)"
output: html_document
---

Note, including additional information like this in the author field may not be ideal as the additional information will also be included in the rendered html author metadata:

<meta name="author" content="My name here I’m on Twitter" />

These questions might also be helpful:

In YAML, how do I break a string over multiple lines?

Split the title onto multiple lines?

like image 149
markdly Avatar answered Sep 29 '22 15:09

markdly