Sweave是R語言的一個函數,其功能是將R的函數整合進Latex或Lyx中。從而可以生成動態報表,當數據或分析改變時,報表能自動得到更新。以下為一個簡單的範例:
\documentclass[a4paper]{article}
\title{Sweave Example 1}
\author{Friedrich Leisch}
\begin{document}
\maketitle
In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:
<<>>=
data(airquality)
library(ctest)
kruskal.test(Ozone ~ Month, data = airquality)
@
which shows that the location parameter of the Ozone
distribution varies significantly from month to month. Finally we
include a boxplot of the data:
\begin{center}
<<fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
@
\end{center}
\end{document}
將以上內容存成example-1.Rnw,在R中執行Sweave("example-1.Rnw")便會產生example-1.tex和相關的圖片檔,再用latex或pdflatex編譯即可,附件有較多的說明與範例。
範例資料來源:Sweave = R · LATEX
下載PDF檔案:https://docs.google.com/open?id=0B65mUklYPhUkemFFbFVEQ3RJNUE
沒有留言:
張貼留言