<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/programming-meh-lets-teach-how-to-write-computational-essays-instead/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.ouseful.info/2017/11/15/programming-meh-lets-teach-how-to-write-computational-essays-instead/"> Rstats – OUseful.Info, the blog…</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>From Stephen Wolfram, a nice phrase to describe the sorts of thing you can create using tools like Jupyter notebooks, Rmd and Mathematica notebooks: <em>computational essays</em> that complements the “computational narrative” phrase that is also used to describe such documents.</p>
<p>Wolfram’s recent blog post <a rel="nofollow" href="http://blog.stephenwolfram.com/2017/11/what-is-a-computational-essay/" target="_blank">What Is a Computational Essay?</a>, part essay, part computational essay,  is primarily a pitch for using Mathematica notebooks and the Wolfram Language. (The Wolfram Language provides computational support plus access to a “fact engine” database that ca be used to pull factual information into the coding environment.)</p>
<p>But it also describes nicely some of the generic features of other “generative document” media (Jupyter notebooks, Rmd/knitr) and how to start using them.</p>
<blockquote>
<p>There are basically three kinds of things [in a computational essay]. First, ordinary text (here in English). Second, computer input. And third, computer output. And the crucial point is that these three kinds of these all work together to express what’s being communicated.</p>
</blockquote>
<p>In Mathematica, the view is something like this:</p>
<p><a rel="nofollow" href="http://blog.stephenwolfram.com/2017/11/what-is-a-computational-essay/" target="_blank"><br>
<img data-orig-file="https://ouseful.files.wordpress.com/2017/11/wolfram_comp_document.png?w=376&amp;h=307&amp;fit=376%2C307&amp;resize=376%2C307" data-orig-size="551,449" data-medium-file="https://ouseful.files.wordpress.com/2017/11/wolfram_comp_document.png?w=376&amp;h=307&amp;fit=376%2C307&amp;resize=376%2C307?w=300" data-attachment-id="17099" data-image-meta="{" data-image-description="" src="https://ouseful.files.wordpress.com/2017/11/wolfram_comp_document.png?w=376&h=307&fit=376%2C307&resize=376%2C307" data-permalink="https://blog.ouseful.info/2017/11/15/programming-meh-lets-teach-how-to-write-computational-essays-instead/wolfram_comp_document/" data-large-file="https://ouseful.files.wordpress.com/2017/11/wolfram_comp_document.png?w=376&amp;h=307&amp;fit=376%2C307&amp;resize=376%2C307?w=551" alt="" data-image-title="Wolfram_comp_document" sizes="(max-width: 376px) 100vw, 376px" data-comments-opened="1" class="wp-image-17099" data-recalc-dims="1"></a></p>
<p>In Jupyter notebooks:</p>
<p><img data-orig-file="https://ouseful.files.wordpress.com/2017/11/baxter_notebook.png?w=341&amp;h=205&amp;fit=341%2C205&amp;resize=341%2C205" data-orig-size="1572,946" data-medium-file="https://ouseful.files.wordpress.com/2017/11/baxter_notebook.png?w=341&amp;h=205&amp;fit=341%2C205&amp;resize=341%2C205?w=300" data-attachment-id="17098" data-image-meta="{" data-image-description="" src="https://ouseful.files.wordpress.com/2017/11/baxter_notebook.png?w=341&h=205&fit=341%2C205&resize=341%2C205" data-permalink="https://blog.ouseful.info/2017/11/15/programming-meh-lets-teach-how-to-write-computational-essays-instead/baxter_notebook/" data-large-file="https://ouseful.files.wordpress.com/2017/11/baxter_notebook.png?w=341&amp;h=205&amp;fit=341%2C205&amp;resize=341%2C205?w=830" alt="" data-image-title="Baxter_notebook" sizes="(max-width: 341px) 100vw, 341px" data-comments-opened="1" class="wp-image-17098" data-recalc-dims="1"></p>
<p>In its raw form, an RStudio Rmd document source looks something like this:</p>
<p><img data-orig-file="https://ouseful.files.wordpress.com/2017/11/rmd_knitr1.png?w=372&amp;h=242&amp;fit=372%2C242&amp;resize=372%2C242" data-orig-size="1238,804" data-medium-file="https://ouseful.files.wordpress.com/2017/11/rmd_knitr1.png?w=372&amp;h=242&amp;fit=372%2C242&amp;resize=372%2C242?w=300" data-attachment-id="17100" data-image-meta="{" data-image-description="" src="https://ouseful.files.wordpress.com/2017/11/rmd_knitr1.png?w=372&h=242&fit=372%2C242&resize=372%2C242" data-permalink="https://blog.ouseful.info/2017/11/15/programming-meh-lets-teach-how-to-write-computational-essays-instead/rmd_knitr/" data-large-file="https://ouseful.files.wordpress.com/2017/11/rmd_knitr1.png?w=372&amp;h=242&amp;fit=372%2C242&amp;resize=372%2C242?w=830" alt="" data-image-title="rmd_knitr" sizes="(max-width: 372px) 100vw, 372px" data-comments-opened="1" class="wp-image-17100" data-recalc-dims="1"></p>
<blockquote>
<p>A computational essay is in effect an intellectual story told through a collaboration between a human author and a computer. …</p>
<p>The ordinary text gives context and motivation. The computer input gives a precise specification of what’s being talked about. And then the computer output delivers facts and results, often in graphical form. It’s a powerful form of exposition that combines computational thinking on the part of the human author with computational knowledge and computational processing from the computer.</p>
</blockquote>
<p>When we originally drafted the OU/FutureLearn course <a rel="nofollow" href="https://www.futurelearn.com/courses/learn-to-code" target="_blank"><em>Learn to Code for Data Analysis</em></a> (also <a rel="nofollow" href="http://www.open.edu/openlearn/science-maths-technology/learn-code-data-analysis/content-section-overview" target="_blank">available on OpenLearn</a>), we wrote the explanatory text – delivered as HTML but including static code fragments and code outputs – as a notebook, and then ‘ran” the notebook to generate static HTML (or markdown) that provided the static course content. These notebooks were complemented by actual notebooks that students could work with interactively themselves.</p>
<p>(Actually, we prototyped authoring both the static text, and the elements to be used in the student notebooks, in a single document, from which the static HTML and “live” notebook documents could be generated: <a rel="nofollow" href="https://blog.ouseful.info/2015/08/21/authoring-multiple-docs-from-a-single-ipython-notebook/" target="_blank">Authoring Multiple Docs from a Single IPython Notebook</a>. )</p>
<p>Whilst the notion of the computational essay <em>as a form</em> is really powerful, I think the added distinction between between <em>generative</em> and <em>generated</em> documents is also useful. For example, a raw Rmd document of Jupyter notebook is a <em>generative</em> document that can be used to create a document containing text, code, and the output generated from executing the code. A <em>generated</em> document is an HTML, Word, or PDF export from an executed <em>generative</em> document.</p>
<p>Note that the generating code can be omitted from the generated output document, leaving just the text and code generated outputs. Code cells can also be collapsed so the code itself is hidden from view but still available for inspection at any time:</p>
<blockquote>
<p>Notebooks also allow “reverse closing” of cells—allowing an output cell to be immediately visible, even though the input cell that generated it is initially closed. This kind of hiding of code should generally be avoided in the body of a computational essay, but it’s sometimes useful at the beginning or end of an essay, either to give an indication of what’s coming, or to include something more advanced where you don’t want to go through in detail how it’s made.</p>
</blockquote>
<p>Even if notebooks are not used interactively, they can be used to create <em>correct</em> static texts where outputs that are supposed to relate to some fragment of code in the main text actually do so <em>because they are created by the code</em>, rather than being cut and pasted from some other environment.</p>
<p>However, making the generative – as well as generated – documents available means readers can learn by doing, as well as reading:</p>
<blockquote>
<p>One feature of the Wolfram Language is that—like with human languages—it’s typically easier to read than to write. And that means that a good way for people to learn what they need to be able to write computational essays is for them first to read a bunch of essays. Perhaps then they can start to modify those essays. Or they can start creating “notes essays”, based on code generated in livecoding or other classroom sessions.</p>
</blockquote>
<p>In terms of our own learnings to date about how to use notebooks most effectively as part of a teaching communication (i.e. as learning materials), Wolfram seems to have come to many similar conclusions. For example, try to limit the amount of code in any particular code cell:</p>
<blockquote>
<p>In a typical computational essay, each piece of input will usually be quite short (often not more than a line or two). But the point is that such input can communicate a high-level computational thought, in a form that can readily be understood both by the computer and by a human reading the essay.</p>
<p>…</p>
<p>So what can go wrong? Well, like English prose, can be unnecessarily complicated, and hard to understand. In a good computational essay, both the ordinary text, and the code, should be as simple and clean as possible. I try to enforce this for myself by saying that each piece of input should be at most one or perhaps two lines long—and that the caption for the input should always be just one line long. If I’m trying to do something where the core of it (perhaps excluding things like display options) takes more than a line of code, then I break it up, explaining each line separately.</p>
</blockquote>
<p>It can also be useful to “preview” the output of a particular operation that populates a variable for use in the following expression to help the reader understand what sort of thing that expression is evaluating:</p>
<blockquote>
<p>Another important principle as far as I’m concerned is: be explicit. Don’t have some variable that, say, implicitly stores a list of words. Actually show at least part of the list, so people can explicitly see what it’s like.</p>
</blockquote>
<p>In many respects, the computational narrative format forces you to construct an argument in a particular way: if a piece of code operates on a particular thing, you need to access, or create, the thing before you can operate on it.</p>
<blockquote>
<p>[A]nother thing that helps is that the nature of a computational essay is that it must have a “computational narrative”—a sequence of pieces of code that the computer can execute to do what’s being discussed in the essay. And while one might be able to write an ordinary essay that doesn’t make much sense but still sounds good, one can’t ultimately do something like that in a computational essay. Because in the end the code is the code, and actually has to run and do things.</p>
</blockquote>
<p>One of the arguments I’ve been trying to develop in an attempt to persuade some of my colleagues to consider the use of notebooks to support teaching is the <em>notebook</em> nature of them. Several years ago, one of the <em>en vogue</em> ideas being pushed in our learning design discussions was to try to find ways of supporting and encouraging the use of “learning diaries”, where students could reflect on their learning, recording not only things they’d learned but also ways they’d come to learn them. Slightly later, portfolio style assessment became “a thing” to consider.</p>
<p>Wolfram notes something similar from way back when…</p>
<blockquote>
<p>The idea of students producing computational essays is something new for modern times, made possible by a whole stack of current technology. But there’s a curious resonance with something from the distant past. You see, if you’d learned a subject like math in the US a couple of hundred years ago, a big thing you’d have done is to create a so-called ciphering book—in which over the course of several years you carefully wrote out the solutions to a range of problems, mixing explanations with calculations. And the idea then was that you kept your ciphering book for the rest of your life, referring to it whenever you needed to solve problems like the ones it included.</p>
<p>Well, now, with computational essays you can do very much the same thing. The problems you can address are vastly more sophisticated and wide-ranging than you could reach with hand calculation. But like with ciphering books, you can write computational essays so they’ll be useful to you in the future—though now you won’t have to imitate calculations by hand; instead you’ll just edit your computational essay notebook and immediately rerun the Wolfram Language inputs in it.</p>
</blockquote>
<p>One of the advantages that notebooks have over some other environments in which students learn to code is that structure of the notebook can encourage you to develop a solution to a problem <em>whilst retaining your earlier working</em>.</p>
<p>The earlier working is where you can engage in the minutiae of trying to figure out how to apply particular programming concepts, creating small, <em>playful</em>, test examples of the sort of the thing you need to use in the task you have actually been set. (I think of this as a “trial driven” software approach rather than a “test driven* one; in a trial,  you play with a bit of code in the margins to check that it does the sort of thing you want, or expect, it to do before using it in the main flow of a coding task.)</p>
<p>One of the advantages for students using notebooks is that they can doodle with code fragments to try things out, <em>and keep a record of the history of their own learning</em>, as well as producing working bits of code that might be used for formative or summative assessment, for example.</p>
<p>Another advantage is that by creating notebooks, which may include recorded fragments of dead ends when trying to solve a particular problem, is that you can refer back to them. And reuse what you learned, or discovered how to do, in them.</p>
<blockquote>
<p>And this is one of the great general features of computational essays. When students write them, they’re in effect creating a custom library of computational tools for themselves—that they’ll be in a position to immediately use at any time in the future. It’s far too common for students to write notes in a class, then never refer to them again. Yes, they might run across some situation where the notes would be helpful. But it’s often hard to motivate going back and reading the notes—not least because that’s only the beginning; there’s still the matter of implementing whatever’s in the notes.</p>
</blockquote>
<p>Looking at many of the notebooks students have created from scratch to support assessment activities in TM351, it’s evident that many of them are not using them other than as an interactive code editor with history. The documents contain code cells and outputs, with little if any commentary (what comments there are are often just simple inline code comments in a code cell). They are barely computational narratives, let alone computational essays; they’re more of a computational scratchpad containing small code fragments, without context.</p>
<p>This possibly reflects the prior history in terms of code education that students have received, working “out of context” in an interactive Python command line editor, or a traditional IDE, where the idea is to produce standalone files containing complete programmes or applications. <em>Not</em> pieces of code, written a line at a time, in a narrative form, with example output to show the development of a computational argument.</p>
<p>(One argument I’ve heard made against notebooks is that they aren’t appropriate as an environment for writing “real programmes” or “applications”. But that’s not strictly true: Jupyter notebooks can be used to <a rel="nofollow" href="https://blog.ouseful.info/2017/09/06/building-a-json-api-using-jupyer-notebooks-in-under-5-minutes/" target="_blank">define and run microservices/APIs</a> as well as <a rel="nofollow" href="https://github.com/oschuett/appmode" target="_blank">GUI driven applications</a>.)</p>
<p>However, if you start to see computational narratives as a form of narrative documentation that can be used to support a form of literate programming, then once again the notebook format can come in to its own, and draw on styling more common in a text document editor than a programming environment.</p>
<p>(By default, Jupyter notebooks expect you to write text content in markdown or markdown+HTML, but <a rel="nofollow" href="https://github.com/genepattern/jupyter-wysiwyg" target="_blank">WYSIWYG editors can be added as an extension</a>.)</p>
<blockquote>
<p>Use the structured nature of notebooks. Break up computational essays with section headings, again helping to make them easy to skim. I follow the style of having a “caption line” before each input. Don’t worry if this somewhat repeats what a paragraph of text has said; consider the caption something that someone who’s just “looking at the pictures” might read to understand what a picture is of, before they actually dive into the full textual narrative.</p>
</blockquote>
<p>As well as allowing you to create documents in which the content is generated interactively – code cells can be changed and re-run, for example – it is also possible to embed interactive components in both generative and generated documents.</p>
<p>On the one hand, it’s quite possible to generate and embed an interactive map or interactive chart that supports popups or zooming in a generated HTML output document.</p>
<p>On the other, Mathematica and Jupyter both support the dynamic creation of interactive widget controls in generative documents that give you control over code elements in the document, such as sliders to change numerical parameters or list boxes to select categorical text items. (In the R world, there is support for <a rel="nofollow" href="http://rmarkdown.rstudio.com/authoring_embedded_shiny.html" target="_blank">embedded shiny apps</a> in Rmd documents.)</p>
<p>These can be useful when creating narratives that encourage exploration (for example, in the sense of  <a rel="nofollow" href="https://blog.ouseful.info/2017/10/24/authoring-interactive-diagrams-and-explorable-explanations/" target="_blank">explorable explantations</a>, though I seem to recall Michael Blastland <a rel="nofollow" href="https://blog.ouseful.info/2011/05/18/quick-summary-of-opening-session-of-visualisation-and-presentation-in-statistics/" target="_blank">expressing concern several years ago</a> about how <em>ineffective</em> interactives could be in data journalism stories.</p>
<blockquote>
<p>The technology of Wolfram Notebooks makes it straightforward to put in interactive elements, like <a rel="nofollow" href="http://reference.wolfram.com/language/ref/Manipulate.html" target="_blank"><tt>Manipulate</tt></a>, [<code>interact</code>/<code>interactive</code> in Jupyter notebooks] into computational essays. And sometimes this is very helpful, and perhaps even essential. But interactive elements shouldn’t be overused. Because whenever there’s an element that requires interaction, this reduces the ability to skim the essay.”</p>
</blockquote>
<p>I’ve also thought previously that interactive functions are a useful way of motivating the use of functions <em>in general</em> when teaching introductory programming. For example, <a rel="nofollow" href="https://blog.ouseful.info/2017/01/10/an-alternative-way-of-motivating-the-use-of-functions/" target="_blank">An Alternative Way of Motivating the Use of Functions?</a>.</p>
<p>One of the issues in trying to set up student notebooks is how to handle boilerplate code that is required before the student can create, or run, the code you actually want them to explore. In TM351, we preload notebooks with various packages and bits of magic; in my own tinkerings, I’m starting to try to package stuff up so that it can be imported into a notebook in a single line.</p>
<blockquote>
<p>Sometimes there’s a fair amount of data—or code—that’s needed to set up a particular computational essay. The cloud is very useful for handling this. Just deploy the data (or code) to the Wolfram Cloud, and set appropriate permissions so it can automatically be read whenever the code in your essay is executed.</p>
</blockquote>
<p>As far as opportunities for making increasing use of notebooks as a kind of technology goes, I came to a similar conclusion some time ago to Stephen Wolfram when he writes:</p>
<blockquote>
<p>[I]t’s only very recently that I’ve realized just how central computational essays can be to both the way people learn, and the way they communicate facts and ideas. Professionals of the future will routinely deliver results and reports as computational essays. Educators will routinely explain concepts using computational essays. Students will routinely produce computational essays as homework for their classes.</p>
</blockquote>
<p>Regarding his final conclusion, I’m a little bit more circumspect:</p>
<blockquote>
<p>The modern world of the web has brought us a few new formats for communication—like blogs, and social media, and things like Wikipedia. But all of these still follow the basic concept of text + pictures that’s existed since the beginning of the age of literacy. With computational essays we finally have something new.</p>
</blockquote>
<p>In many respects, HTML+Javascript pages have been capable of delivering, and actually delivering, computationally generated documents for some time. Whether computational notebooks offer some sort of step-change away from that, or actually represent a return to the <a rel="nofollow" href="http://news.bbc.co.uk/1/hi/technology/4132752.stm" target="_blank">original read/write imaginings of the web</a> with portable and computed facts accessed using Linked Data?</p>
<p> <a rel="nofollow" href="https://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/17096/" target="_blank"><img border="0" alt="" src="https://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/17096/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></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="https://blog.ouseful.info/2017/11/15/programming-meh-lets-teach-how-to-write-computational-essays-instead/"> Rstats – OUseful.Info, the blog…</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 alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/FLoqm2Ifo9Y" height="1"></a></div>