~/Week 2

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Coding Standards for R

  1. Always use text files/text editor
  2. Indent your code
  3. Limit the width of your code (80 columns?)
  4. Author suggests indentation of 4 spaces at minimum
  5. Limit the length of individual functions

What is Markdown?

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it structurally to valid XHTML/HTML

Markdown Syntax

*This text will appear italicized!*

This text will appear italicized!

**This text will appear bold!**

This text will appear bold

## This is a secondary heading

###This is a tertiary heading

This is a secondary heading

This is a tertiary heading

Unordered Lists

- first item in list

- second item in list

Ordered lists

1. first item in list

2. second item in list

3. third item in list

  1. first item in list
  2. second item in list
  3. third item in list

Create links

[Download R](http://www.r-project.org/)

Download R

Advanced linking

I spent so much time reading [R bloggers][1] and [Simply Statistics][2]!

[1]: http://www.r-bloggers.com/ "R bloggers"

[2]: http://simplystatistics.org/ "Simply Statistics"

I spent so much time reading R bloggers and Simply Statistics!

Newlines require a double space after the end of a line

What is Markdown?

Created by John Gruber and Aaron Swartz. It is a simplified version of “markup” languages. It allows one to focus on writing as opposed to formatting. Markdown provides a simple, minimal, and intuitive way of formatting elements.

You can easily convert Markdown to valid HTML (and other formats) using existing tools.

What is R Markdown?

R Markdown is the integration of R code with markdown. It allows one to create documents containing “live” R code. R code is evaluated as part of the processing of the markdown and its results are inserted into the Markdown document. R Markdown is a core tool in literate statistical programming

R Markdown can be converted to standard markdown using knitr package in R. Markdown can then be converted to HTML using the markdown package in R. This workflow can be easily managed using R Studio. One can create powerpoint like slides using the slidify package.

Problems, Problems

One of the ways to resolve this is to simply put the data and code together in the same document so that people can execute the code in the right order, and the data are read at the right times. You can have a single document that integrates the data analysis with all the textual representations.

Literate Statistical Programming

Literate Statistical Programming

How Do I Make My Work Reproducible?

Literate Programming: Pros

Literate Programming: Cons

What is Knitr Good For?

What is knitr NOT good for?

Non-GUI Way of Creating R Markdown documents

setwd(<working directory>)

A few notes about knitr

Processing of knitr documents

Inline Text Computations

You can reference variable in RMarkdown through the following

`The current time is `r time`. My favorite random number is `r rand`

Setting Global Options

Example for suppressing all code chunks

​```{r setoptions, echo=FALSE}
opts_chunk$set(echo=False, results = "hide")

Some Common Options

Caching Computations

Caching Caveats

Summary of knitr