Skip to content

Instantly share code, notes, and snippets.

@1beb
Created August 13, 2012 11:55
Show Gist options
  • Save 1beb/3339966 to your computer and use it in GitHub Desktop.
Save 1beb/3339966 to your computer and use it in GitHub Desktop.
Example of reproducible research in Rstudio documents
setwd('path/to/Example.Rnw/')
Sweave('Example.Rnw')
texi2pdf('Example.tex')
% Preamble
\documentclass{Article}
\usepackage{Sweave}
% Start Document
\begin{document}
% Titlepage
\begin{titlepage}
\title{A Title}
\author{Author's Name}
\date {\today}
\maketitle
\end{titlepage}
% Content Begins
\section{A Linear Regression}
Here, we generate some sample data. By default, sweave echoes the results - showing
us what commands are run in R. But we can stop that in our code chunk by specifying
"echo=FALSE". In the example below, we will generate random variables from the
normal and uniform distribution, put them in a data frame, run a linear regression
and output a table that shows us the pertinent information from the regression.
% R Code Chunk
<>=
library(xtable)
set.seed(1234) # Set seed for RNG
x >=
plot(fit, which=1)
@
% End Document
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment