Stat Bytes: R Workflow Tips with RStudio, Shiny, knitr

Jerzy Wieczorek, 2/10/2014

Reproducible Research / Literate Programming

RStudio Tips

# (Setting eval=FALSE for this code chunk, in order to just show the code
# but not run it)

# Set up data for a model, y = beta*x + e
x = 1:30
beta = 0.2

# Let's function-ify this code and call the function `lmplot`: Select these
# four lines of code, and go to Code > Extract Function
e = rnorm(length(x))
y = beta * x + e
plot(x, y, main = "y = x + e")
abline(lm(y ~ x))

# Now we can run our new lmplot function
lmplot(x = 1:50, beta = 0.2)

Shiny