{"id":3069,"date":"2015-11-03T10:56:15","date_gmt":"2015-11-03T18:56:15","guid":{"rendered":"http:\/\/blogs.reed.edu\/ed-tech\/?p=3069"},"modified":"2016-05-16T22:22:06","modified_gmt":"2016-05-17T05:22:06","slug":"r-markdown-senior-thesis-template","status":"publish","type":"post","link":"https:\/\/blogs.reed.edu\/ed-tech\/2015\/11\/r-markdown-senior-thesis-template\/","title":{"rendered":"R Markdown senior thesis template"},"content":{"rendered":"<p>\u201cScience is reportedly in the middle of a reproducibility crisis.\u201d This is the claim of quite a few these days including an article from <a href=\"https:\/\/ropensci.org\/blog\/2014\/06\/09\/reproducibility\/\">ROpenSci<\/a> which directly references another article by <a href=\"http:\/\/theconversation.com\/science-is-in-a-reproducibility-crisis-how-do-we-resolve-it-16998\">The Conversation<\/a>. But what is \u201creproducible research\u201d and how can statistical tools be used to help facilitate it?<\/p>\n<p><!--more--><\/p>\n<div class=\"container-fluid main-container\">\n<p>I agree with Roger Peng and the folks behind Coursera\u2019s massively popular Data Science Specialization and the front page of their <a href=\"https:\/\/www.coursera.org\/course\/repdata\">Reproducible Research course<\/a> on their definition of \u201creproducible research\u201d:<\/p>\n<blockquote><p>Reproducible research is the idea that data analyses, and more generally, scientific claims, are published with their data and software code so that others may verify the findings and build upon them. The need for reproducibility is increasing dramatically as data analyses become more complex, involving larger datasets and more sophisticated computations. Reproducibility allows for people to focus on the actual content of a data analysis, rather than on superficial details reported in a written summary. In addition, reproducibility makes an analysis more useful to others because the data and code that actually conducted the analysis are available.<\/p><\/blockquote>\n<p>One of the current goals at Reed is for students to be engaged in the research process earlier on in their academic careers in order to make their senior thesis experience more meaningful and rewarding. The collecting and analysis of data has been a challenging part of this process in the past for students. Additionally, updating statistical analyses, plots, and bibliographies as advisors request has sometimes been time consuming and frustrating.<\/p>\n<p>So how does this tie into the reproducible research concept? As more and more students use <em>R Markdown<\/em> while taking courses at Reed (Chem 101\/102, Mathematics 141, Mathematics 243, and Bio 101\/102 next year!), it became clear that an option to use <em>R Markdown<\/em> while generating the senior thesis document should be available. The simplicity of <em>Markdown<\/em> commands improves readability and documentation, which make it a great thesis writing environment. <em>R Markdown<\/em> provides a wonderful environment to publish data and software code along with text and commentary and, in my opinion, is the best software currently available for writing journal areedtemplates, homework assignments, <strong>AND<\/strong> senior theses\u2026.reproducible senior theses!<\/p>\n<p>What I\u2019ll be discussing in this blog post is a template I\u2019ve created using <em>R Markdown<\/em> for Reed College senior theses. This template derives a lot of the features of the current LaTeX template (in fact it directly calls this template) so you can expect many of the great things from that including automatic creation of figure and table numbers, a table of contents, easy addition of beautiful plots and graphics, and the use of bibiolography style files. (Do you really want to have to memorize what APA or MLA looks like?\u2026No!) In addition, you won\u2019t need to learn LaTeX. I\u2019ve done the hard work of getting all that set up. You only need to learn <em>Markdown<\/em>. (Don\u2019t worry. That\u2019s really not hard!)<\/p>\n<div id=\"markdown\" class=\"section level3\">\n<h3>Markdown<\/h3>\n<p><em>Markdown<\/em> allows you to write in an easy-to-read, easy-to-write plain text format, which then converts to a variety of different formats. <em>R Markdown<\/em>, which is really just <em>Markdown<\/em> with the ability to add in <strong>R<\/strong> code and output directly, allows you to produce HTML, PDF, and even Word documents based on only one <em>Markdown<\/em> file! The sky is the limit for <em>Markdown<\/em>!<\/p>\n<p>The thesis template will automatically convert the <em>Markdown<\/em> code you type to LaTeX code which will then produce a PDF document. Again, I\u2019ve done the hard work of getting this <em>Markdown<\/em> code to produce the correct output. If you\u2019d like to check out the current version of this PDF, it is available on Google Drive <a href=\"https:\/\/drive.google.com\/a\/reed.edu\/file\/d\/0BxWNSFPtAdfxQ2p5dUdmUGtYcVE\/view?usp=sharing\">here<\/a>.<\/p>\n<p>Now, back to <em>Markdown<\/em> basics. You can find a lot more information on <em>Markdown<\/em> <a href=\"https:\/\/help.github.com\/articles\/markdown-basics\/\">here<\/a> and an interactive tutorial <a href=\"http:\/\/markdowntutorial.com\/\">here<\/a>. You\u2019ll get used to it before you know it. Probably in less than an hour!<\/p>\n<\/div>\n<div id=\"install-the-template-generating-package\" class=\"section level3\">\n<h3>Install the template generating package<\/h3>\n<p>After you\u2019ve stepped through the basics of <em>Markdown<\/em>, it\u2019s time to check out this template for yourself. Make sure you have RStudio and LaTeX installed and then direct your browser to the GitHub page for the template: <a href=\"http:\/\/github.com\/ismayc\/reedtemplates\">http:\/\/github.com\/ismayc\/reedtemplates<\/a>. You\u2019ll see instructions there in the <code>README.md<\/code> file near the bottom of the page on installing the template package and getting the template running. As you see there, you\u2019ll want to install the <code>reedtemplates<\/code> package via the following commands in the RStudio console:<\/p>\n<pre class=\"r\"><code>install.packages(\"devtools\")\r\ndevtools::install_github(\"ismayc\/reedtemplates\")<\/code><\/pre>\n<p>This allows for <strong>Reed Senior Thesis<\/strong> to be an option when you create a new R Markdown file via the File -&gt; New File -&gt; R Markdown dialog. You can specify the name you would like to give the file and also the location where you\u2019d like the template and its files to be stored. I\u2019ve called it \u201cMyReedThesis\u201d in what follows. After hitting the OK button, you\u2019ll see an Rmd file load up onto your RStudio window. (It will be called the same thing as what you specified in the previous step.)<\/p>\n<p>If you click on the folder you\u2019ve just created in the Files tab in RStudio, you can see a lot of files that have been created to assist you. You will see Rmd files for the abstract, bibliography, different chapters, conclusion, and your main Rmd file (<code>MyReedThesis.Rmd<\/code> for me). You also see folders that hold your bibliography database files (<code>bib<\/code>), bibliography style files (<code>csl<\/code>), data files (<code>data<\/code>), and images (<code>figure<\/code>). You\u2019ll find that I\u2019ve preloaded a bibliography database file (<code>thesis.bib<\/code>), an American Psychological Association (APA) style file (<code>apa.csl<\/code>) from the <a href=\"https:\/\/www.zotero.org\/styles\">Zotero Style Repository<\/a>, a dataset derived from departing flights from Seattle and Portland in 2014 (<code>flights.csv<\/code>), and a couple figures in the <code>figure<\/code> folder.<\/p>\n<p>If you click on the <strong>Knit<\/strong> button near the top of the RStudio window on your main Rmd file, a PDF linking together all of the files will be created. I\u2019ve tried to show you how to do a variety of things in this <code>Markdown<\/code> template including<\/p>\n<p><strong>In the Introduction<\/strong><\/p>\n<ul>\n<li>Creating a different headers including a chapter using the <code>#<\/code> syntax, a section using <code>##<\/code>, a subsection using <code>###<\/code>, etc.<\/li>\n<li>Bolding of text by surrounding the text in <code>**<\/code> or <code>__<\/code><\/li>\n<li>Adding a comment using the <code>&lt;!--<\/code> and <code>--&gt;<\/code> syntax<\/li>\n<\/ul>\n<p><strong>In Chapter 1<\/strong><\/p>\n<ul>\n<li>Easily creating numbered or non-numbered lists<\/li>\n<li>Using whitespace to create a new paragraph in your output<\/li>\n<li>Including <strong>R<\/strong> code in chunks to be added into your document<\/li>\n<li>Specifying different chunk options to tweak the output<\/li>\n<li>Using inline <strong>R<\/strong> code for calculations and directly referring to <strong>R<\/strong> results in the text of your document<\/li>\n<li>Including plots created in <strong>R<\/strong><\/li>\n<li>Creating tables based on data stored in <strong>R<\/strong><\/li>\n<li>Creating hyperlinks to web resources<\/li>\n<\/ul>\n<p><strong>In Chapter 2<\/strong><\/p>\n<ul>\n<li>Including mathematical equations<\/li>\n<li>Using LaTeX to create chemical reaction equations<\/li>\n<li>Adding other discipline specific content to your theses<\/li>\n<\/ul>\n<p><strong>In Chapter 3<\/strong><\/p>\n<ul>\n<li>Creating tables using <em>Pandoc<\/em><\/li>\n<li>Labelling and referencing tables and figures (both created in <strong>R<\/strong> and stored in files) using custom <strong>R<\/strong> functions I created<\/li>\n<li>Adding footnotes into your document<\/li>\n<li>Developing bibliography database files using Zotero (highly recommended) or other programs like BibDesk<\/li>\n<\/ul>\n<p><strong>In the Conclusion<\/strong><\/p>\n<ul>\n<li>Making a few tweaks to how chapters are displayed<\/li>\n<li>Creating appendices if desired<\/li>\n<\/ul>\n<p>Lastly, in the <code>bibliography.Rmd<\/code> file, you\u2019ll find ways to currently fix the hanging indent issue with some citation styles. (You might need to delete a few lines if your style doesn\u2019t require hanging indents.) I also provide a way to cite sources in your bibliography at the end of the document that you don\u2019t directly cite throughout your thesis here.<\/p>\n<\/div>\n<div id=\"the-main-driver-r-markdown-file\" class=\"section level3\">\n<h3>The main driver R Markdown file<\/h3>\n<p>If you go back to the main Rmd file that is open, you\u2019ll see a lot of text that is commented out. This provides more information about what is happening in this file. In summary, this file links all of the chapter files together and creates a way to input the preliminaries (the abstract, the preface, etc.) as either inline text at the top of the document or in a file stored like <code>abstract.Rmd<\/code>. You\u2019ll also change your name, your advisor\u2019s name, and other metadata here. One last thing: <code>lot<\/code> stands for \u201cList of Tables\u201d and <code>lof<\/code> stands for \u201cList of Figures.\u201d These are automatically created when you include a table or a figure into your theses.<\/p>\n<p>Currently, everything links throughout the document as well. When you make a reference to <code>Figure 3.1<\/code> in Chapter 2, you can click on that link in the PDF and it will go directly to that figure. Chapters and sections are also linked in this same fashion.<\/p>\n<p>There will be slight modifications (hopefully only slight if any at all!) occurring to this document as students and faculty test it throughout this year. I highly recommend running <code>devtools::install_github(\"ismayc\/reedtemplates\")<\/code> and creating a new template from time to time to make sure you have the latest version of the template. You can easily copy your files into the new template as needed. (Some of the changes may occur to LaTeX files that you won\u2019t directly access.)<\/p>\n<p>I\u2019m hopeful that this template will be of great use to seniors throughout Reed College this year and in years to come. Science majors may get the most immediate benefit, but I believe that <em>Markdown<\/em> is an incredibly valuable language to learn. It\u2019s easy and extremely flexible in the type of output it can produce. I\u2019ve written this template to be as user friendly as possible and I hope that non-science majors will consider using it! If you have any questions, feedback, or would like to report any issues, please email me at\u00a0cismay@reed.edu.<\/p>\n<p>(The generating R Markdown file for this HTML document\u2014saved in the .Rmd extension\u2014is available <a href=\"http:\/\/reed.edu\/data-at-reed\/software\/R\/blogposts\/rmd_template_blogpost.Rmd\">here<\/a>.)<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u201cScience is reportedly in the middle of a reproducibility crisis.\u201d This is the claim of quite a few these days including an article from ROpenSci which directly references another article by The Conversation. But what is \u201creproducible research\u201d and how can statistical tools be used to help facilitate it?<\/p>\n","protected":false},"author":1244,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,32,33],"tags":[40,87],"class_list":["post-3069","post","type-post","status-publish","format-standard","hentry","category-general-instructional-technology","category-programming","category-quantitative-analysis","tag-r","tag-reproducible-research"],"_links":{"self":[{"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/posts\/3069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/users\/1244"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/comments?post=3069"}],"version-history":[{"count":6,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/posts\/3069\/revisions"}],"predecessor-version":[{"id":3198,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/posts\/3069\/revisions\/3198"}],"wp:attachment":[{"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/media?parent=3069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/categories?post=3069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.reed.edu\/ed-tech\/wp-json\/wp\/v2\/tags?post=3069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}