Skip to content

Instantly share code, notes, and snippets.

@mamacneil
Created October 31, 2018 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamacneil/0d715e4714689ef281be284a706d0fb1 to your computer and use it in GitHub Desktop.
Save mamacneil/0d715e4714689ef281be284a706d0fb1 to your computer and use it in GitHub Desktop.
Lecture 9 - Living Documents
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Living documents\n",
"\n",
"Today's lecture is a bit outside of Jupyter (or I haven't yet figured out how to do it well within Jupyter), so sit back and relax as I take you through some outside of Jupyter examples.\n",
"\n",
"Among the most useful things scripting for a programming language provides is the ability to program out the various steps in an analysis so that, should the underlying data change, you can quickly re-run everything and get a revised result. This utility also extends to plotting, where one script conducts the analysis and a second script re-creates all the plots. Yet this entire process can be taken to its logical conclusion, where code, plots, and text are all intermingled so that figures and any numbers in the text are dynamic, even possibly the text itself. \n",
"\n",
"There are a few key elements needed to to implement living documents in R:\n",
"\n",
" 1. R\n",
" 2. Text\n",
" 3. LaTeX\n",
" 4. Glue\n",
"\n",
"The fourth element comes in various forms -- [knitr](https://yihui.name/knitr/) was an early standout -- but today we're going to look at [R-Markdown](https://rmarkdown.rstudio.com), which is a great reason to use the popular [RStudio](https://www.rstudio.com), a GUI-wrapper for R that provides a clean layout that some people prefer. RStudio also fund great people (i.e. [H Wickham](http://hadley.nz)) to contribute a boatload of [useful packages](https://www.rstudio.com/products/rpackages/), many of which we've already seen."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## LaTex\n",
"\n",
"Computer programmer [Leslie Lamport](https://en.wikipedia.org/wiki/Leslie_Lamport) created LaTeX in the 1980's as a typsetting language that - in stark contrast to the WYSIWYG fussing of Word - separates the design and layout of documents from the writing itself. This [separation of content and presentation](https://en.wikipedia.org/wiki/Separation_of_content_and_presentation) design philosophy allows you to write stuff quickly without any care as to how it looks until the end (if at all). LaTeX is popular among physicists and statisticians, in part because they're code-savy, but also because LaTeX does an excellent job rendering equations relatively quickly. So well in fact that [Word now accepts LaTeX](https://support.office.com/en-us/article/linear-format-equations-using-unicodemath-and-latex-in-word-2e00618d-b1fd-49d8-8cb4-8d17f25754f8) notation in its (awful) equation editor, and it is available in R-Markdown as well to typeset equations within the text body. \n",
"\n",
"Come to think of it, so does Jupyter! \n",
"\n",
"\n",
"$$S_n = \\frac{X_1 + X_2 + \\cdots + X_n}{n}\n",
" = \\frac{1}{n}\\sum_{i}^{n} X_i$$\n",
"\n",
"\n",
"$\\LaTeX{}$ Cheatsheet: [https://wch.github.io/latexsheet/](https://wch.github.io/latexsheet/)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## RStudio\n",
"\n",
"Once you have RStudio up and running, the key elements needed are:\n",
"\n",
" install.packages(\"rmarkdown\")\n",
"\n",
" install.packages(\"rticles\")\n",
"\n",
"`R-Markdown` provides a Jupyter-like workflow mixture of code and graphics that make up the bulk of the living document. `rticles` provides the bibliography support to bulid a proper reference list and use in-line citations (which are awesome).\n",
"\n",
"With these things in place, we can create some living documents:"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"**Stuff happens...**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Outshot\n",
"\n",
"[Good enough practices in scientific computing](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005510#sec009) - By Greg Wilson, Jennifer Bryan, Karen Cranston, Justin Kitzes, Lex Nederbragt, Tracy K. Teal"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quiz!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# What have you learned and what's next?\n",
"\n",
"The point of today's lab was to learn about living document creation outside of Jupyter\n",
"\n",
"**You should at this point be comfortable:**\n",
" 1. Using R-Markdown\n",
" 2. Knowing $\\LaTeX{}$ exists\n",
" 3. Shamelessly using templates\n",
"\n",
"Next week we will hit the final frontier - graphics!\n",
"\n",
"\n",
"---\n",
"# ** A bientôt ** !"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment