how to include an abstract in a Rmd file
Asked Answered
M

2

12

In a .Rmd file with the header below, I want to include an abstract, so I tried the standard LateX article form,

\abstract{This paper explores a variety of topics related to the question of testing the equality of
covariance matrices in multivariate linear models, particularly in the MANOVA setting. 
The main focus is on graphical methods that can be used to understand features of data related
to this question.}

But, surprisingly (I know this seems weird), the references in my References section become badly formatted -- no spacing between references, odd indentations. So, how can I include something that looks like an abstract?

My YAML header is:

---
title: "Notes on Testing Equality of Covariance Matrices"
author: "Michael Friendly"
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
  pdf_document:
    fig_caption: yes
    keep_tex: yes
    number_sections: yes
    includes:
        in_header: mystyles.tex
 csl: apa.csl
bibliography: 
  - "C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/statistics.bib"
  - "C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/graphics.bib"
---

Edit: Thinking this over, the problem may be that pandoc-citeproc is somehow confused by something done by using \abstract{} in the document.

Merozoite answered 2/4, 2016 at 13:35 Comment(0)
A
24

The rmarkdown package now allows for including an abstract in your YAML. Like so:

abstract: "This is my abstract."

See this blog post for an example.

Arching answered 2/4, 2016 at 18:39 Comment(5)
That is perfect, even if it is surprising that an abstract goes in the YAML header. Thanks also for the link to that blog post by Steve Miller -- very helpful.Merozoite
Do you know if there is a way to change the word "Abstract" that appears in the document, to something else (i.e. to translate it to another language)?Swap
If you are producing HTML output, I think you'll need to modify the template: see "Custom Templates" in rmarkdown.rstudio.com/html_document_format.html. For LaTeX output, see this page: tex.stackexchange.com/questions/82993/…Packer
The template in the blog post isn't necessary to include an abstract. Just putting that line in your YAML will suffice.Wolenik
NOTE: I noticed that when the abstract has a comma in it AND the abstract text is NOT in quotes, the abstract text gets truncated at the comma. The solution of course is to put the abstract text in quotes. This answer does that but in case you run into this, you know what to do.Casanova
R
0

I suggest the alternative method by creating reports from multiple R Markdown files. It adds a lot of useful features like cross-referencing which are very useful for longer documents.

---
abstract: |
  `r paste(readLines("front-and-back-matter/_abstract.Rmd"), collapse = "\n  ")`
---
Reprehensible answered 1/7, 2024 at 8:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.