Chapter 2 Title page and abstract

2.1 An introduction to YAML

YAML is the top level settings controlling most of the formatting of your article. When you are writing papers with R, this is also where information such as authors and coauthors, affiliations and abstract goes. The formatting of the YAML is unfortunately quite journal specific, but, this is also the most specific part of the paper, so although you may have to do edits to the YAML when submitting papers to Springer, Elsevier or APA, the main body of the paper, including the introduction, methods, results, discussion, tables and figures do not require changes.

2.1.1 A minimal YAML header

---
title: "Untitled"
author: "Tormod"
date: "22 10 2018"
output: html_document
---

YAML is used to specify many options regarding your paper. The example above is the minimum requirements, and will produce a html_document, dated 22 10 2018, authored by Tormod with Untitled as the title. When writing papers with r your YAML will include many more options.

The example below, is perhaps a more realistic example from an actual paper.

2.1.2 A realistic YAML header

---
title: "Interplay of Subjective and Objective Economic Well-Being on 
the Mental Health of Norwegian Adolescents"
author:
  - name: Tormod Bøe
    email: tormod.boe@uni.no
    affiliation: UNI,UIB
    footnote: Corresponding Author
  - name: Keith Petrie
    email: kj.petrie@auckland.ac.nz
    affiliation: UA
  - name: Børge Sivertsen
    email: Borge.Sivertsen@fhi.no
    affiliation: FHI,HF
  - name: Mari Hysing
    email: Mari.Hysing@uib.no
    affiliation: UIB
    
address:
  - code: UNI
    address: Uni Research Health, Regional Centre for Child and Youth Mental Health 
    and Child Welfare, Bergen, Norway
  - code: UA
    address: Department of Psychological Medicine, University of Auckland, 
    Auckland, New Zealand
  - code: FHI
    address: Department of Health Promotion, Norwegian Institute of Public Health, 
    Bergen, Norway
  - code: HF
    address: Department of Research and Innovation, Helse Fonna HF, Haugesund, Norway
  - code: UIB
    address: Department of Psychosocial Science, Faculty of Psychology, 
    University of Bergen, Bergen, Norway.

abstract: |
 __Purpose:__ Objective and subjective socioeconomic status (SES) are important
determinants of adolescent mental health problems. Research has demonstrated 
independent associations of both to mental health problems, but less is known 
about their association and interplay in contributing to mental health problems.  
 __Methods:__ Data from the youth@hordaland study, a large survey of 9079 
Norwegian 16-19 year old's, were linked to tax register information about 
household income, and used to examine correspondence between perceived economic 
well-being and household income, and how perceptions of economic well-being 
interacted with household income in their associations with adolescent mental 
health problems.   
 __Results:__ The Spearman correlation $\rho$ between perceived and actual 
household income was -0.293. Correspondence was somewhat higher among adolescents 
with low and high household income compared to adolescents with intermediate 
household income. Low income and unfavorable perceptions of economic well-being was 
associated with most mental health outcomes independent of perceived economic 
well-being. Importantly, the mental health benefits associated with higher 
income appeared to depend on the adolescents’ perceptions of their family’s 
relative economic position.
 __Conclusions:__ The correspondence between perceived and actual income was 
reasonable. Adolescents with low household income experience more mental health
problems compared to their more affluent peers, but higher incomes were not 
associated with fewer mental health problems among those with less favorable 
perceptions of their family's economic rank. Additional work is need to understand
how adolescents establish perceptions of rank, and whether they are 
amenable for intervention.  
 

keywords: Adolescence, Mental health, Income, Subjective SES, youth@hordaland

journal: "Journal of Adolescent Health"
date: "`r Sys.Date()`"
# bibliography: mybibfile.bib
# citation_package: "natbib"
# csl: "journal-of-adolescent-health.csl"

layout: 3p
output:
  bookdown::pdf_book:
    base_format: rticles::elsevier_article
    number_sections: false
    # latex_engine: xelatex

bibliography: "/Users/st06810/Dropbox/References/zotero.bib"
# biblio-style: apalike
csl: journal-of-adolescent-health.csl

classoption: oneside

header-includes:
  - \usepackage{threeparttable}
  - \usepackage{threeparttablex}
  - \usepackage{longtable}
  - \usepackage{lscape}
  - \usepackage[counterclockwise]{rotating}
  - \usepackage[english]{babel}
  - \usepackage[nolists,tablesfirst]{endfloat}
  - \DeclareDelayedFloatFlavour*{longtable}{table}
  - \DeclareDelayedFloatFlavour*{sidewaystable}{table}
---

And will result in a paper that will look like Figure 2.1 when formatted as pdf.

Example paper formatted for Elsevier journals

Figure 2.1: Example paper formatted for Elsevier journals

Wheras some of the YAML options are relatively self-explanatory (e.g., title, author, affiliation, abstract and keywords), others, such as journal, layout, classoption and header-includes control the overall layout of the output and stylistic elements in the body of the paper. This is also an example of using templates from the rticles package, to format a paper according for submission to an Elsevier journal. Of importance is that intendation is crucial when writing YAML, as illustrated in Figure 2.2.

You will eventually get this

Figure 2.2: You will eventually get this

The rticles package is interesting to look at, and currently supports (and has templates for producing) papers formatted for submission to many publishers: acm_article, acs_article, aea_article, amq_article, ams_article, asa_article, biometrics_article, copernicus_article, ctex, elsevier_article, ieee_article, jss_article, mdpi_article, mnras_article, peerj_article, plos_article, pnas_article, rjournal_article, rsos_article, rss_article, sage_article, sim_article, springer_article.

All of these leverages latex templates, and will produce a nicely formatted pdf file. For those of you who are able to submit pdfs (and work alone) this will get you very far. For the rest of us, this is merely a starting point, and the pdf will have often to be converted to a Word file for collaboration and submission. More on that later.