RR MarkdownRmd LaTex template. No drama!bookdown::pdf_document2:Talking R Markdown, probably the main distinction between writing a reproducible report of your analysis or a journal article is the journal template and layout which is often provided as a LaTeX template by the editors. In my view, if you want to write your robust and reproducible paper in R today, you are faced with two options based on whether the journal you want to submit to has a LaTex template already built in R Markdown.
R Markdownrticles packageHave a look at the rticles package to see if your journal is listed there. This package is a collaborative effort to create Rmd LaTeX templates for various journals.
install.packages("rticles")
# Or the dev version
# devtools::install_github("rstudio/rticles")
library(rticles)
BiocWorkflowTools package: F1000 LaTex template for Bioconductor workflowsIf you work in Bioinformatics and you developed a Bioconductor workflow then you might want to submit your paper to F1000 and the BiocWorkflowTools is exactly what you need!
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install('BiocWorkflowTools')
library(BiocWorkflowTools)
Once you found your journal, create a new Rmd and choose your template as in Figure 1!
Figure 1: Choose your rticles template.
The journal template will offer all the necessary examples to show you how to cross reference sections, figures, tables and equations as well as you can check the final result by knitting the document.
Let’s try an example!
Rmd LaTex template. No drama!RmdThe first thing that I did was to decide what I wanted.
I had a few journals in mind but not one defined: I needed a general structure (main manuscript with sections, additional files)
I wanted a robust way to cross-reference figures/tables/euqations/sections
I wanted to be able to output the article in both pdf, word and LaTex to come towards my co-authors and how they are used to give feedbacks
I wanted to include a bibliography files
I wanted to be able to create a file of additional information where tables and figures would be numbered distinctly from the main manuscript (e.g. S1, S2 etc…)
bookdown is the answer!bookdown approachYAML of you Rmd to combine different Rmd with site: bookdown::bookdown_site and tweak the LaTex headers to achieve more flexibility in figure numbering..bib file by adding bibliography: biblio.bib in the YAMLReports, articles and books can be easily generated using the library(bookdown). This package was written to allow a flexible and comprehensve environment to author books in R and the author, Yihui Xie, made the same framework available to write single documents. Writing everyday reproducible documents or journal articles requires a very similar infrastructure and, at the end of the day, there is very little substantial difference between them. Yihui wrote a super comprehensive book https://bookdown.org/yihui/bookdown/ about all things bookdown! Once you master one type of document, you are pretty well set to master them all!
bookdown::pdf_document2:In the bookdown-article-minimal-example/ folder I created a minimal example to create an article with bookdown.
YAML setupThe YAML is what you need to define the layout or theme of your documents. You can also add plain LaTex code in here and tell bookdown how you want your Rmd files to be knitted together. By default, bookdown bind together files in numerical order. For example, see the Rmd files in the bookdown-article-minimal-example/ folder. The firt part would be index.Rmd, followed by 02-Additional_files and 03-References.Rmd.
bookdown cross-referencing approach---
title: "A minimal paper"
author: "Anna Quaglieri"
output:
bookdown::pdf_document2:
toc: no
keep_tex: true
---
bookdown::bookdown_site---
title: "A minimal paper"
author: "Anna Quaglieri"
site: bookdown::bookdown_site
output:
bookdown::pdf_document2:
toc: no
keep_tex: true
author: |
| Author 1^[Corresponding author: email@email.com] $^1$, Author 2 $^1$, Author 3 $^2$
| $^1$Affiliation1, $^2$Affiliation2
abstract: |
Your abstract goes here...
bibliography: biblio.bib
---
I found the following LaTex code on this StackOverflow thread.
---
title: "A minimal paper"
author: "Anna Quaglieri"
output:
bookdown::pdf_document2:
toc: no
keep_tex: true
author: |
| Author 1^[Corresponding author: email@email.com] $^1$, Author 2 $^1$, Author 3 $^2$
| $^1$Affiliation1, $^2$Affiliation2
abstract: |
Your abstract goes here...
bibliography: biblio.bib
fontsize: 12pt
header-includes:
\usepackage{float} \floatplacement{figure}{H}
\newcommand{\beginsupplement}{\setcounter{table}{0} \renewcommand{\thetable}{S\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{S\arabic{figure}}}
\usepackage{setspace}\doublespacing
\usepackage{lineno}
\linenumbers
---
LaTex options: line numbering and spacing!YAML!---
\usepackage{setspace}\doublespacing
\usepackage{lineno}
\linenumbers
---
\usepackage{endfloat} after header-includes: in the YAMLNow that you are setup with the YAML stucture you can start populating your manuscript with for figures, tables, equations, code and texts! In the minimal example that I created I created two separated Rmd files for the main manuscript and the additional files. This is because the manuscript could become really long and you might be better of splitting the two parts.
bookdown: Authoring Books and Technical Documents with R Markdown
Interface R with Overleaf https://medium.com/@arinbasu/a-tutorial-on-how-to-interface-an-r-notebook-with-overleaf-11f23c306cfd
Minimal bookdown template for scientific papers http://landscapeportal.org/blog/2017/09/06/r-markdown-template-for-a-scientific-manuscript/
Earo Wang papers on GitHub and helpful suggestions via email!
Written by Anna Quaglieri