Created
April 18, 2012 16:51
-
-
Save ramnathv/2414974 to your computer and use it in GitHub Desktop.
Looping Through a Data Frame with Sweave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate PDF for a Pid | |
gen_pdf <- function(sdf){ | |
rnw_file <- sprintf("%s.rnw", unique(sdf$Pid)) | |
tex_file <- sub('.rnw$', '.tex$', rnw_file) | |
file.copy('template.Rnw', rnw_file) | |
Sweave(rnw_file) | |
tools::texi2pdf(tex_file, clean = TRUE, quiet = TRUE) | |
unlink(c(rnw_file, tex_file)) | |
} | |
# Loop through all unique Pids | |
library(plyr) | |
d_ply(df, .(Pid), gen_pdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{graphicx} | |
\begin{document} | |
\SweaveOpts{concordance=TRUE} | |
% Modify the text as needed. Note that sdf is a subset of the original | |
% data frame for a given Pid. | |
This is the report for \Sexpr{unique(sdf$Pid)}. | |
% Generate the plot | |
<<plot, fig = T, width = 5, height = 5>>= | |
plot(sdf$ksap1, sdf$ksap2) | |
@ | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment