Tutorial 7: Exporting Your Work

DPI R Bootcamp

Jared Knowles


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


plot of chunk tradeoff

Get the tools

A Simple Example

#' This is some text

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

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

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)

#' 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 Example

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

# A plot and some text
qplot(readSS, mathSS, data = df, alpha = I(0.2)) + geom_smooth()