'RMarkdown YAML section add author's hyperlink email to footer
In the YAML section of the RMarkdown file, I want write the author's name and email address and have that only appear in the footer of the document. Here is an example of the concept (code does not actually run):
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body:
author: Apple Pie [I want this to be the email hyperlink]
email: [email protected] [but this can also be the hyperlink]
---
My file structure: I have a main folder called rainbow_folder. Inside rainbow_folder are two folders called red_folder (my working directory) and blue_folder. The red folder contains my .Rmd file, and the blue folder contains additional files (e.g. header_logo.html - which is used in my YAML's before_body)
edit: My output must be an html.
Relevant searches: I prefer a solution that does not force me to change the pandoc template. Using the Author field of R Markdown in footer.html
I have also tried the Footer and header solution from this post as well. However, I do not want a solution that changes the author name in the html file. I want my output to look similar to the image in this post. https://holtzy.github.io/Pimp-my-rmd/#footer_and_header
Edit: Hack solution to put it at the end of the body
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
params:
name: Apple Pie
email: [email protected]
---
{r your_code_here}
df %>% dput()
<p>Author: `r params$name` </p>
<p>Email: `r params$email` </p>
Solution 1:[1]
The after body include does not work like that. It expects the name of a file containing an html fragment to be included as the footer because the knitting process is programmed to send that file name to Pandoc's --include-after-body
option. Here is the relevant section in the Pandoc User's Guide.
Here is an approach that I think is in the spirit of what you want to do. It makes use of parameterized reporting. Your Rmarkdown file could start something like this:
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body: ../blue_folder/after.html
self_contained: false
params:
github: holtzy
author: Yan Holtz
email: [email protected]
twitter: r_graph_gallery
linkedin: yan-holtz-2477534a
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
writeLines(
sprintf(
'
<hr />
<div class="footer">
<p style="text-align: center;">A work by <a href="https://github.com/%s/">%s</a></p>
<p style="text-align: center;"><span style="color: #808080;"><em><a href="mailto:%s">%s</a></em></span></p>
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
<p style="text-align: center;">
<a href="https://twitter.com/%s?lang=en" class="fa fa-twitter"></a>
<a href="https://www.linkedin.com/in/%s/" class="fa fa-linkedin"></a>
<a href="https://github.com/%s/" class="fa fa-github"></a>
</p>
</div>
',
params$github,
params$author,
params$email,
params$email,
params$twitter,
params$linkedin,
params$github
),
'../blue_folder/after.html'
)
```
The approach here is that during the knitting process, the parameter values are substituted into the format string and written out to a new file called "after.html" in your "blue_folder". Then this html fragment is included after the body of your Rmarkdown.
The results look like this:
A caveat to this approach is that I needed to set the document to not be self-contained with self_contained: false
so that I could use external css to get the font-awesome icons.
You can, of course, edit the html fragment to your liking and perhaps find a different way to load font-awesome that allows for a default self-contained knit.
Solution 2:[2]
This is one option. You can use latex
packages in the YAML
section of a markdown file to add a footer note with a hyperlink email. The package fancyhdr
is for the footers and hyperref
is for the hyperlink for your email. This option is created in an pdf markdown. You can use the following code:
---
title: "My Title"
author: "Apple Pie"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{hyperref}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{\href{mailto:[email protected]}{Apple Pie}}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
\thispagestyle{fancy}
The output looks like this:
As you can see, the footnote is at the bottom of the page and if you click on it, you will directly go to that mail.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Quinten |