R Sweave Example

The previous post “Writing a Book Using R” described using latex for writing a book, saving time with one master bibliography and other organizational devices. Sweave allows R code to be included in a latex file. This is a good marriage; while latex provides typeset text; R is statistically and graphic oriented.

Here is an example of the overall steps one would take to compile a combined latex and R code document for publication.

Part of the latex is generated by the Sweave package in R, not R itself. For example, you need to first run Sweave(”script.R”) in the R console. This passes the latex you write untouched, and processes the R commands, particularly plot() that produces plots. There is also a package called xtable that produces latex from data.frames, and model result and time series objects. To you it you run your analysis, store the results in the appropriate object like a model, data.frame or time.series then call xtable(x) and all the results come out in formatted latex.

With the latex, you then compile it with any of the compilers, e.g. a typical sequence that would automatically do all the table of contents, bibliography, index, figure and table references and list of steps would be:

  1. Sweave(“master.R”) — done in R
  2. pdflatex master — on the command line
  3. bibtex master — does the bibliography
  4. makeindex master — makes the index
  5. pdflatex master — put bibliography and index in
  6. pdflatex master — does the cross referencing

This should produce the finished pdf ready to print with the results of analysis, figures, and everything collated.


19 thoughts on “R Sweave Example

  1. Pingback: kliknij tutaj

  2. Pingback: wypozyczalnia samochodow Gliwice

  3. Pingback: list your startup

  4. Pingback: wynajem samochodow

  5. Pingback: steroids legal

  6. Pingback: http://www.sofia-massage-naturiste.fr

  7. Pingback: web page

  8. Pingback: try

  9. Pingback: how to fuck

  10. Pingback: kliknij link

  11. Pingback: newborn sleep

  12. Pingback: zobacz

  13. Pingback: zobacz tutaj

  14. Pingback: Zenerect

  15. Pingback: navigate to these guys

  16. Pingback: Free Your Mind Online

  17. Pingback: witryna www

  18. Pingback: Netforce

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s