Search code examples
rsweave

R Sweave chunk options


Say I have two chunks of code seen below,

<<include=FALSE>>=
inf.col <- cbind(dffits(col.lm), dfbetas(col.lm), cooks.distance(col.lm))
inf.col462 <- data.frame(inf.col[462,])
rownames(inf.col462) <- c("DFFITS", "DBETAS Intercept", "DBETAS Accept", "DBETAS Top10perc", "DBETAS PrivateYes", "DBETAS Outstate", "DBETAS PhD", "Cook's D")
inf.col462
inf.col484 <- data.frame(inf.col[484,])
rownames(inf.col484) <- c("DFFITS", "DBETAS Intercept", "DBETAS Accept", "DBETAS Top10perc", "DBETAS PrivateYes", "DBETAS Outstate", "DBETAS PhD", "Cook's D")
inf.col484
inf.col251 <- data.frame(inf.col[251,])
rownames(inf.col251) <- c("DFFITS", "DBETAS Intercept", "DBETAS Accept", "DBETAS Top10perc", "DBETAS PrivateYes", "DBETAS Outstate", "DBETAS PhD", "Cook's D")
inf.col251
inf.col460 <- data.frame(inf.col[460,])
rownames(inf.col460) <- c("DFFITS", "DBETAS Intercept", "DBETAS Accept", "DBETAS Top10perc", "DBETAS PrivateYes", "DBETAS Outstate", "DBETAS PhD", "Cook's D")
inf.col460
@

<<>>=
inf.col2 <- cbind(inf.col462, inf.col484, inf.col251, inf.col460)
inf.col2
@

And in my .pdf output I only want to see the code from the second chunk. But the second chunk utilizes code from the first chunk. So if I use <<eval=FALSE>>= the code will not run at all and R won't know what the objects inf.col462, etc. even are. I tried <<include=FALSE>>= as shown, but it still prints all of the code from chunk 1.

How can I not print chunk 1, but store it's info in cache to evaluate chunk 2?

Thank you.

P.S. I have required: dplyr, knitr, tidyr.


Solution

  • I solved this issue using <<results=hide>>=. It doesn't display the output but still keeps it in memory for later chunks of code. Thanks!