{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Project Jupyter talk for R North-East group\n", "## January 2016" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Jupyter lets you create interactive documents containing text and code + output" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Many languages are supported, including **Ju**lia, **Py**thon and **R**" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Good tool for (a) documenting an analysis in one file (b) interactive R use" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "The main interface is the \"Jupyter notebook\" - a web app that runs in the browser" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Project background\n", "\n", "Jupyter is an open source project written in Python\n", "\n", "It's a spin-off of \"IPython\" - similar project for notebooks containing Python code only \n", "\n", "R support is quite new so not a lot of documentation yet!" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Notebook file format\n", "\n", "Notebooks are stored as JSON objects \n", "\n", "These contain full details of current session\n", "\n", "So you can immediately view someone's analysis by opening a file\n", "\n", "And then modify and rereun parts if you choose" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Notebook capabilities\n", "\n", "Below I list some things that a Jupyter notebook can display" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Input can be plain text" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Or markdown, allowing for easy formatting features" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "e.g. \n", "\n", "1. _italics_, **bold** \n", "2. Equations (using latex): \n", "$\\int_{-\\infty}^\\infty e^{-\\theta^2} \\sin \\theta\\ d\\theta$\n", "3. Lists!\n", "4. [Hyperlinks](https://en.wikipedia.org/wiki/Hyperlink)\n", "5. Raw HTML:
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Explanatory text can be mixed with code." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Let's estimate $\\int_0^1 x^3 dx$ by Monte Carlo integration (correct answer is 0.25)\n", "\n", "i.e. I'll simulate uniform random points in the unit square and find the proportion below the graph of $x^3$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "0.247" ], "text/latex": [ "0.247" ], "text/markdown": [ "0.247" ], "text/plain": [ "[1] 0.247" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = 1000; x = runif(n, 0, 1); y = runif(n, 0, 1)\n", "mean(y < x^3)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "library(repr)\n", "options(repr.plot.width=10, repr.plot.height=4)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "scrolled": false, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "