R Programming/Publication quality output

Formatting numbers
You can use the  function to control the number of digits and other characteristics of a displayed object.

Sweave
Sweave is a literate programming language which integrates LaTeX and R code. The Sweave file generates a LaTeX file and an R file which can in turn be compiled. Roger Koenker, Meredith and Racine (2009) and Charles Geyer argue that Sweave favors reproducible econometric/statistical research.

There are some alternatives to Sweave for literate programming. One of them is Babel which is included in Emacs Orgmode. This tool allow export to LaTeX and HTML. It is also possible to include code chunks for various programming languages (R, Ruby, etc).

Syntax
The main idea is that you write a file which includes LaTeX and R code. LaTeX code begins with @ and R code with <<>>= (some options can be included between << and >>).

The file is stored with extension .Rnw or .rnw. At the end, you extract from this file an R file using Stangle and a LaTeX file using Sweave. Here is an example with a file called <tt>file.Rnw</tt> which generates <tt>file.tex</tt> and <tt>file.R</tt>

Then you can run LaTeX on your file.tex. This can be done using the <tt>system</tt> function or <tt>texi2dvi</tt>.

Note that you may need to download Sweave.sty from the internet since it is not part of the standard MikTeX distribution.

You can also add your results in your text using the <tt>\Sexpr{}</tt> function.

Options
There are some options. These options can be included for each code chunk or in the Sweave command.

By default, figures are exported as pdf and eps files. If you only want one format suppress the other one with <tt>pdf=F</tt> or <tt>eps=F</tt> option.
 * For figures, you can either include them in the tex file using <tt>fig=T</tt> or not include them using <tt>fig=F</tt>.
 * The R code can be displayed in the tex file using <tt>echo=T</tt>. If you don't want to include it in the tex file, use <tt>echo=F</tt>.
 * The R code can be evaluated using <tt>eval=T</tt>. If you don't want to evaluate the R code, use <tt>eval=F</tt>.
 * The results :
 * <tt>results=tex</tt> treats the output as LaTeX code
 * <tt>results=verbatim</tt> treats the output as Verbatim (the default)
 * <tt>results=hide</tt> does not include the results in the LaTeX output

These options can be passed to the <tt>Sweave</tt> function.

They can also be passed to each code chunk.

Text editor for Sweave
The main issue with Sweave is that few text editors include syntax highlighting for Sweave. Here are some exceptions :
 * RStudio is a very good solution. It is easy to install and use and it includes buttons to run Sweave files.
 * Vim provides syntax highlighting for Sweave file (R no web syntax)
 * Emacs + ESS (Emacs Speaks Statistics) provides full support for Sweave file. It includes a keyboard shortcut to run Sweave files and syntax highlighting switching between LaTeX and R.
 * Eclipse StatET plugin provides support for Sweave (LaTeX/R) documents with all basic features (syntax highlighting, bracket matching, toggle comment, ...) and with detection of R chunks.

Pubprint
Pubprint is a small utility that is able to transform the output of statistical tests to publication ready output. Pubprint is able to export outputs to severall formats (HTML, LaTeX, Markdown and plain text), but unfortunately supports only the APA style (publication style of the American Psychological Association). However, this style is widely used and may be appropriate in more cases.

Example
Obviously pubprint prints a LaTeX formatted string, but changing the output format is possible (according to the manual pubprint is intended to use with knitr and detects output format automatically if it is used with it):

The output can be pasted into a documented or may included in a knitr/sweave <tt>\Sexpr{}</tt> statement.

Export to LaTeX
R has lots of functions which allow it to export results to LaTeX.

General functions
<tt>toLatex</tt> in the utils package.
 * Note that <tt>toLatex</tt> does not handle matrices.
 * <tt>toLatex</tt> has been adapted to handle matrices and ftables in the memisc package.


 * <tt>mat2tex</tt> (sfsmisc) exports matrix to LaTeX.
 * <tt>tex.table</tt> (cwhmisc) package exports a dataframe into a LaTeX table.


 * <tt>xtable</tt> (xtable) exports various objects, including tables, data frames, lm, aov, and anova, to LaTeX.

See also :
 * The highlight package by Romain François exports R code to LaTeX and HTML.
 * <tt>format.df</tt> and <tt>latex</tt> in the Hmisc package.
 * The MEMISC and the quantreg packages include other <tt>latex</tt> function.

Descriptive statistics

 * estout package.
 * The reporttools package include some functions for table of descriptive statistics.

Estimation results

 * The stargazer package provides an easy way to export the results of regressions to LaTeX
 * texreg provides the same kind of features.
 * The estout package provides functions similar to the Stata's <tt>esttab</tt> and <tt>estout</tt> utilities . Estimates are stored using <tt>eststo</tt> and printed using <tt>esttab</tt>. They can be exported to CSV and LaTeX. These functions support <tt>lm</tt>, <tt>glm</tt> and <tt>plm</tt> objects (see plm package).
 * <tt>apsrtable</tt> (apsrtable) exports the results of multiple regression to LaTeX in a way similar to the American Political Science Review publication standard.
 * The <tt>xtable</tt> (xtable package) exports dataframes, matrix, estimation results . <tt>xtable</tt> can also be used to export the results to an HTML file.
 * The <tt>outreg</tt> function developped by Paul Johnson is similar to the Stata <tt>outreg</tt> function. See "R you ready ?" post on this topic.
 * <tt>mtable</tt> and <tt>toLatex</tt> in the 'memisc package.

Export to HTML
The rpublisher is a literate programming language which publish results in HTML (it is based on python and was last updated in 2008).

See R2HTML, xtable, hwriter, prettyR, highlight, HTMLUtils

<tt>wiki.table</tt> in the hacks package export a matrix or a dataframe into Mediawiki table markup (as used on this wiki and many others).