Tutorial 7: Exporting Your Work

DPI R Bootcamp

Jared Knowles

Overview

In this lesson we hope to learn:

Why does Export Matter?

Generating a basic report

  1. Include the data, source code, and output together in one package
  2. Have the source code available for raw data to finished product
  3. Present figures, tables, and code in a single document

A few terms

Beginning

plot of chunk tradeoff

Get the tools

A Simple Example

#' This is some text
#'

# + myplot, dev='svg',out.width='500px',out.height='400px'

library(ggplot2)
data(diamonds)
qplot(carat, price, data = diamonds, alpha = I(0.3), color = clarity)

#' Diamond size is clearly related to price, but not in a linear fashion.
#'

Converting the Script

o <- spin("C:/Path/To/myscript.R", knit = FALSE)
knit2html(o, envir = new.env())

Example Script II

#' This is some text that I want to explain
#' For example, this plot is important, let's look below

# + myplot,
# dev='svg',out.width='500px',out.height='400px',warning=FALSE,message=FALSE

library(ggplot2)
load("PATH/TO/MY/DATA.rda")
qplot(readSS, mathSS, data = df, alpha = I(0.2)) + geom_smooth()

#' There is not a linear relationship, but it sure is close.
#' Let's do some regression
#'

test <- lm(mathSS ~ readSS + factor(grade), data = df)
summary(test)

#' It's all statistically significant

Spin 2

o <- spin("C:/Path/To/myscript2.R", knit = FALSE)
knit2html(o, envir = new.env())
# We specify that new environment is used to carry out the analysis, not
# the current environment

Stitch

Stitch Example

## title: My Super Report ## Author: Mr. Data ##

# A plot and some text
library(ggplot2)
library(xtable)
load("PATH/TO/MY/DATA")
qplot(readSS, mathSS, data = df, alpha = I(0.2)) + geom_smooth()