Sweave

from Wikipedia, the free encyclopedia

Sweave is a function that was written by Friedrich Leisch for the statistical software R and is implemented there in the utils package . Sweave creates a dynamic connection between R and LaTeX . LaTeX is a software system for using the text typesetting TeX . B. scientific texts can be written.

Sweave enables the linking of R-Code and LaTeX commands. During the runtime of the R program, the selected R outputs are combined with the LaTeX commands to form a LaTeX file.

Statistical programs such as R are often used when evaluating data. This can result in tables, graphics and statistics that are to be used in a publication. If a large number of analysis results have arisen, then it is very tedious to insert the desired analysis data (possibly by hand) into the document to be created. With Sweave, the analysis results created in R can be automatically transferred to the LaTeX document.

Sweave can be briefly referred to as a “report generator”. The final LaTeX document contains the running text as well as R-code and selected R-editions. The instructions and outputs that are ultimately to be included in the LaTeX document can be selected by specifying various options. The document can therefore be easily updated if, for example, data should be changed or other calculations should be carried out.

The advantage of Sweave is not only the automatic insertion of analysis results in a LaTeX document, but also the ease with which the target document can be changed when calculations or data are changed.

By publishing program code, the procedure for calculations carried out, statistics and graphics etc. can be better understood by third parties. This means that the results can be easily reproduced and checked, provided the data are available.

Procedure with Sweave

First, a LaTeX file is created in which

<< OPTIONS >> =

R statements

@

R commands can be inserted. The specification of various options enables the R output to be controlled within the LaTeX document.

The file can be converted into a file that can be translated by LaTeX within R with the command Sweave (.). The R instructions and the R output are converted into LaTeX instructions. The file created in this way can be processed further with the help of various LaTeX compilers. So z. For example, a PDF file can be created with PdfTeX .

literature

Web links

Wikibooks: GNU R: Automation and dynamic document  creation - learning and teaching materials