<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/reproducible-research-write-your-clinical-chemistry-paper-using-r-markdown/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/"> The Lab-R-torian</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>Abstract</strong></p>
<div>
<div>
<p><strong>Background:</strong> This blog post is going to show you how to write a reproducible article in the field of clinical chemistry using R Mardkown. The only thing that will change for journal to journal will be the reference fomating and perhaps section numbering. The source code itself will be provided so that you can use it as a template.</p>
<p><strong>Methods:</strong> The paper will use R, R-Markdown, bookdown and pandoc. The references will be taken care of using BibTeX and reference formatting will be managed with Zotero csl files.</p>
<p><strong>Results:</strong> The result will be a manuscript that anyone can reproduce.</p>
<p><strong>Conclusions:</strong> R Markdown makes reproducible research through literate programming pretty easy.</p>
</div>
</div>
<div>
<h1><span>1</span> Background</h1>
<p>Last week at the <a rel="nofollow" href="https://www.msacl.org/" target="_blank">MSACL</a> conference <a rel="nofollow" href="https://faculty.mdanderson.org/profiles/keith_baggerly.html" target="_blank">Dr. Keith Baggerly</a> from <a rel="nofollow" href="https://www.mdanderson.org/research/departments-labs-institutes/departments-divisions/bioinformatics-and-computational-biology.html" target="_blank">MD Anderson Cancer Centre’s Bioformatics and Computational Biology Group</a> spoke about the importance of reproducible research using the <a rel="nofollow" href="http://www.nytimes.com/2011/07/08/health/research/08genes.html" target="_blank">Duke University ovarian cancer biomarker scandal</a> as a backdrop. The talk…was…incredible and illustrated how easy it is to introduce catastrophic errors into your research papers through the use of GUI analytical tools. The now retracted article that Baggerly dismantled is <a rel="nofollow" href="https://www.nature.com/articles/nm1491.epdf?referrer_access_token=GgTgb-wUTsKNRw8OVEiON9RgN0jAjWel9jnR3ZoTv0NW9rGpa6nJwwOU6XHtudagmmBJv2qoOFXJDOLGy16Gidwm_R8x_nqWC3-114LE5H3SScoWgmIQdaw7K2tHqMs9GpXdkbxm5UnBCXTU7ML2PxT0oPNvGTCRf77UNxBWFRsFi3ZFes90JzqRk43GrQU3wnzBirtqhyyW2gWDk0xLm8XrIKW7RAZF3B6m2iJBSWs%3D&tracking_referrer=www.nytimes.com" target="_blank">here</a>. I urge everyone in our field to watch similar talks from Keith discussing biomarker analysis in <a rel="nofollow" href="https://www.youtube.com/watch?v=j1MT0oZqPXY" target="_blank">mass spectrometric proteomic data</a> and <a rel="nofollow" href="https://www.youtube.com/watch?v=7gYIs7uYbMo" target="_blank">microarray data</a>. <a rel="nofollow" href="http://www.feinberg.northwestern.edu/faculty-profiles/az/profile.html?xid=17992" target="_blank">Shannon Haymond</a> and I were then discussing how to make a submission in the field of clinical chemistry that is reproducible. While this article will not discuss the <a rel="nofollow" href="http://rmarkdown.rstudio.com/authoring_basics.html" target="_blank">basics of R and R Markdown</a>, it will serve as a guide for those who know a little about these and give you a working YAML header and get the citations and cross-references correct.</p>
</div>
<div>
<h1><span>2</span> Overhead</h1>
<div>
<h2><span>2.1</span> YAML</h2>
<p>RMarkdown articles require a <a rel="nofollow" href="https://en.wikipedia.org/wiki/YAML" target="_blank">YAML</a> header to instruct R Markdown how to process your article. This is the YAML code that worked for me. I am sure there are other ways to do this:</p>
<pre>---
title: &quot;Reproducible Research: Write your Clinical Chemistry paper using R Markdown&quot;
author: 
- Daniel Holmes, MD
date: &quot;February 04, 2018&quot;
documentclass: &quot;article&quot;
header-includes:
   - \usepackage{amsmath}
output:
  #bookdown::pdf_document2:
  #bookdown::word_document2
  bookdown::html_document2:
    toc: no
    pandoc_args: [
      &quot;--csl&quot;, &quot;clinical-chemistry.csl&quot; , &quot;--citation-abbreviations&quot;, &quot;abbreviations.json&quot;
    ]
bibliography: bibliography.bib
abstract: |
  **Background:** Put
  
  **Methods:** Your
  
  **Results:** Abstract
  
  **Conclusions:** Here
  
keywords: &quot;bla bla bla&quot;
---</pre>
<p>Indenting and spacing really matter a lot in YAML so don’t mess with them. You can generate PDF, MS Word or HTML output as needed by uncommenting and commenting out the output type as appropriate in the YAML above.</p>
</div>
<div>
<h2><span>2.2</span> CSL Files</h2>
<p><a rel="nofollow" href="http://citationstyles.org/" target="_blank">CSL files</a> take care of citation formatting for you. Depending on what journal you are making submission to, you will need a different .csl file. They exist for every conceivable journal. In the world of non-reproducible reports, this process is taken care of by reference managers in GUI word processors but since GUI word processors do not produce reproducible research, we must break up with them.</p>
<p>From the YAML, you will see that you need a file called <a rel="nofollow" href="https://github.com/citation-style-language/styles/blob/5e38d2aabba638edabfb9603388ea3d425d63fd1/dependent/clinical-chemistry.csl" target="_blank">“clinical-chemistry.csl”</a> which I downloaded from <a rel="nofollow" href="https://github.com/citation-style-language/styles" target="_blank">here</a>. Put this file in the same folder as your R Markdown file. The <a rel="nofollow" href="http://clinchem.aaccjnls.org/" target="_blank">Clinical Chemistry</a> .csl depends on <a rel="nofollow" href="https://github.com/citation-style-language/styles/blob/master/american-association-for-cancer-research.csl" target="_blank">the .csl file of the American Association for Cancer Research</a> but it will be downloaded for you on the fly. If you need a different reference format, search the <a rel="nofollow" href="https://github.com/citation-style-language/styles" target="_blank">CSL GitHub repository</a> for the appropriate file.</p>
</div>
<div>
<h2><span>2.3</span> BibTeX</h2>
<p>Reference management in R Markdown is taken care of by <a rel="nofollow" href="http://www.bibtex.org/" target="_blank">BibTeX</a>. You can see from the YAML that we need a bibliography text file called “bibliography.bib”. You can name it whatever you like but you will need to change the YAML accordingly. In any case, any citation you intend to make will have to be in the .bib file. I am going to cite <a rel="nofollow" href="http://www.feinberg.northwestern.edu/faculty-profiles/az/profile.html?xid=17992" target="_blank">Shannon Haymond</a> because this article was her idea and I will toss in a couple of other references so you can see that they get cited in order as we would like.</p>
<p>Below is my bibliography.bib file. I put it in the same folder as my R Markdown file. You make a .bib file using a text file editor (or RStudio) by cutting and pasting the BibTex citations from <a rel="nofollow" href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/scholar.google.com" target="_blank">Google Scholar</a></p>
<pre>@article{shannon2017,
  title={Contribution of symmetric dimethylarginine to GFR decline in pediatric chronic kidney disease},
  author={Brooks, Ellen R and Haymond, Shannon and Rademaker, Alfred and Pierce, Christopher and Helenowski, Irene and Passman, Rod and Vicente, Faye and Warady, Bradley A and Furth, Susan L and Langman, Craig B},
  journal={Pediatric Nephrology},
  pages={1--8},
  year={2017},
  publisher={Springer}
}

@article{li2017wellness,
  title={Wellness Initiatives: Benefits and Limitations},
  author={Li, Michelle and Diamandis, Eleftherios P and Paneth, Nigel and Yeo, Kiang-Teck J and Vogt, Henrik and Master, Stephen R},
  journal={Clinical Chemistry},
  volume={63},
  number={6},
  pages={1063--1068},
  year={2017},
  publisher={Clinical Chemistry}
}

@article{holmes2005preanalytical,
  title={Preanalytical influences on DPC IMMULITE 2000 intact PTH assays of plasma and serum from dialysis patients},
  author={Holmes, Daniel T and Levin, Adeera and Forer, Barry and Rosenberg, Frances},
  journal={Clinical Chemistry},
  volume={51},
  number={5},
  pages={915--917},
  year={2005},
  publisher={Clinical Chemistry}
}</pre>
</div>
<div>
<h2><span>2.4</span> Journal Abbreviations</h2>
<p>Now, the fussiest thing I had to do was get the references abbreviating properly. We need an abbreviation database. Fortunately, I could download the abbreviation database from the Web of Science as a .csv file and then convert it to a JSON file. This was Stephen’s idea. I had to deal with a couple of badly behaving characters from some journal titles. This script, if embedded in your document, will download the .csv for you and then make the abbreviation database for you. That way your citations will say, “J Clin Pathol” and not “Journal of Clinical Pathology” etc.</p>
<pre>```{r, echo = FALSE}
library(RJSONIO)
if(!file.exists(&quot;abbreviations.json&quot;)){
download.file(&quot;https://ndownloader.figshare.com/files/5212423&quot;,&quot;wos_abbrev_table.csv&quot;)
  abbrev &lt;- read.csv(&quot;wos_abbrev_table.csv&quot;, sep = &quot;;&quot;, header = TRUE, stringsAsFactors = FALSE)
  abbrev$full &lt;- gsub(&quot;\\&quot;, &quot;\\\\&quot;,abbrev$full, fixed = TRUE)
  abbrev.list &lt;- list('default' = list('container-title' = abbrev$abbrev.dots))
  names(abbrev.list$default$`container-title`) = abbrev$full
  write(toJSON(abbrev.list), &quot;abbreviations.json&quot;)
  rm(abbrev)
  rm(abbrev.list)
}
```</pre>

</div>
<div>
<h2><span>2.5</span> Citation Management</h2>
<p>Now we can proceed to cite articles from our .bib file freely inserting syntax like this: <code>[@shannon2017]</code>. Shannon wrote this interesting article on symmetric dimethylarginine <span>(1)</span>, Stephen wrote about wellness initiatives with Dr. Diamandis <span>(2)</span> and Dan wrote a paper about PTH when he was a resident <span>(3)</span>. That makes for a total of 3 citations in this manuscript. <span>(1–3)</span></p>
</div>
</div>
<div>
<h1><span>3</span> Reporting Your Results</h1>
<div>
<h2><span>3.1</span> Figures</h2>
<p>You can embed figures in R Markdown as local images or hyperlinks as follows:</p>
<p><code>![Grumpy Cat does not care about reproducibility](grumpy.jpg)</code></p>
<div>
<p><img alt="Grumpy Cat does not care about reproducibility" src="https://i2.wp.com/labrtorian.com/wp-content/uploads/2018/02/grumpy.jpg?w=604" data-recalc-dims="1"></p>
<p>Grumpy Cat does not care about reproducibility</p>
</div>
<p>If you need to do cross-referencing of figures in your document which will change automatically for you if you insert another figure, you can do this by inserting your figure with an R code-chunk and giving the code-chunk a name.</p>
<pre>```{r ancient-aliens, fig.height=3, fig.width=2, fig.cap=&quot;This is the ancient aliens guy.&quot;, echo = FALSE}
knitr::include_graphics('ancient_aliens.jpg')
```</pre>

<div><span></span><br>
<img alt="This is the ancient aliens guy." src="https://i0.wp.com/labrtorian.com/wp-content/uploads/2018/02/ancient_aliens.jpg?w=604" data-recalc-dims="1">
<p>Figure 3.1: This is the ancient aliens guy.</p>
</div>
<p>Then you can reference your code chunk using syntax like this: See figure <code>\@ref(fig:ancient-aliens)</code></p>
<p>and you will automatically create appropriately cross-referenced figures that get automatically numbered like this: See figure <a rel="nofollow" href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/#fig:ancient-aliens" target="_blank">3.1</a>. Of course the hallmark of the reproducibility to embed R code right into the document. See for example figure <a rel="nofollow" href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/#fig:example-code" target="_blank">3.2</a></p>
<pre>```{r example-code, fig.cap = &quot;This is a reproducible figure&quot;}
set.seed(10)
x &lt;- runif(100,0,100)
y &lt;- x + rnorm(100,0,0.10)*x
plot(x,y,
main = &quot;Reproducible Figure&quot;,
pch = 16,
col = &quot;blue&quot;,
xlab = &quot;Current Method (mmol/L)&quot;,
ylab = &quot;New Method (mmol/L)&quot;)
abline(lm(y~x), col = &quot;red&quot;, pch = 2)
```</pre>

<div>
<p> </p>
<p><img alt="This is a reproducible figure" src="https://i2.wp.com/labrtorian.com/wp-content/uploads/2018/02/example-code-1.png?w=604" data-recalc-dims="1"></p>
<p>Figure 3.2: This is a reproducible figure</p>
</div>
</div>
<div>
<h2><span>3.2</span> Inline Calculations</h2>
<p>When you are reporting your amazing results you can have inline code calculations by syntax that looks like this: <code> &amp;#96r round(median(x),1)&amp;#96</code> and would result in the median value of <span>\(x\)</span> being reported as 43.9 mmol/L.</p>
</div>
<div>
<h2><span>3.3</span> Tables</h2>
<p>Tables are not a problem either and can be made with the <code>kable()</code> function of the <a rel="nofollow" href="https://yihui.name/knitr/" target="_blank">knitr</a> package or with the <a rel="nofollow" href="https://cran.r-project.org/web/packages/xtable/index.html" target="_blank">xtable</a> package. Tables can be crossreferenced analogously to figures. See table <a rel="nofollow" href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/#tab:example-table" target="_blank">3.1</a></p>
<pre>```{r example-table, echo = FALSE, results = 'asis'}
library(knitr)
a &lt;- 1:5
b &lt;- 2:6
c &lt;- a*b
z &lt;- data.frame(a,b,c)
kable(z,
  caption = &quot;This is a great table&quot;, 
  col.names = c(&quot;First&quot;,&quot;Second&quot;, &quot;Third&quot;))
```</pre>

<table>
<caption><span>Table 3.1: </span>This is a great table</caption>
<thead>
<tr>
<th align="right">First</th>
<th align="right">Second</th>
<th align="right">Third</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">1</td>
<td align="right">2</td>
<td align="right">2</td>
</tr>
<tr>
<td align="right">2</td>
<td align="right">3</td>
<td align="right">6</td>
</tr>
<tr>
<td align="right">3</td>
<td align="right">4</td>
<td align="right">12</td>
</tr>
<tr>
<td align="right">4</td>
<td align="right">5</td>
<td align="right">20</td>
</tr>
<tr>
<td align="right">5</td>
<td align="right">6</td>
<td align="right">30</td>
</tr>
</tbody>
</table>
</div>
<div>
<h2><span>3.4</span> Math</h2>
<p>Math works pretty magically using <span>\(\LaTeX\)</span> syntax. For example inline math can be done like so <code>$\sin^2x + \cos^2x = 1$</code>. This will result in: <span>\(\sin^2x + \cos^2x = 1\)</span>. And math can also be done as a code block like so:</p>
<pre>$$
\oint_S {E_n dA = \frac{1}{{\varepsilon _0 }}} Q_{inside}
$$</pre>
<p>Gauss’ Law says: <span>\[<br>
\oint_S {E_n dA = \frac{1}{{\varepsilon _0 }}} Q_{inside}<br>
\]</span></p>
<p>Equations can be cross-referenced just like tables and figures.</p>
</div>
</div>
<div>
<h1><span>4</span> Conclusion</h1>
<p>I hope this makes writing a reproducible paper easier for you. A minimal template to produce output in PDF is <a rel="nofollow" href="http://labrtorian.com/wp-content/uploads/2018/02/Template.zip" target="_blank">here</a>. And the PDF output itself is <a rel="nofollow" href="http://labrtorian.com/wp-content/uploads/2018/02/Rmd_paper_template.pdf" target="_blank">here</a>. You’ll need <span>\(\LaTeX\)</span> installed of course.</p>
<p> </p>
<p><strong>Parting Thought</strong></p>
<p>You can cite books too and get Greek letters too:</p>
<p>“Very truly I tell you,” Jesus answered, “before Abraham was born, <span>\(\varepsilon\gamma\omega\)</span> <span>\(\varepsilon\iota\mu\iota\)</span> (I Am)!” <span>(4)</span></p>
</div>
<div>
<h1>References</h1>
<div>
<div>
<p>1. Brooks ER, Haymond S, Rademaker A, Pierce C, Helenowski I, Passman R, et al. Contribution of symmetric dimethylarginine to gfr decline in pediatric chronic kidney disease. Pediatr Nephrol. Springer; 2017;1–8.</p>
</div>
<div>
<p>2. Li M, Diamandis EP, Paneth N, Yeo K-TJ, Vogt H, Master SR. Wellness initiatives: Benefits and limitations. Clin Chem. Clinical Chemistry; 2017;63:1063–8.</p>
</div>
<div>
<p>3. Holmes DT, Levin A, Forer B, Rosenberg F. Preanalytical influences on DPC IMMULITE 2000 intact PTH assays of plasma and serum from dialysis patients. Clin Chem. Clinical Chemistry; 2005;51:915–7.</p>
</div>
<div>
<p>4. John the A, Chist J, Spirit H, God F. The Gospel According to John, 8:58. 1 Heavenly Way: Hosannah Press; 80AD.</p>
</div>
</div>
</div>
<p></p>
<p><br>
</p>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://labrtorian.com/2018/02/05/reproducible-research-write-your-clinical-chemistry-paper-using-r/"> The Lab-R-torian</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/wyDgixkj_QM" height="1"></a></div>