Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

A few days ago I saw a post on how to setup a SweaveR, which would allow for a user to directly export things like tables, graphs, etc. into Latex. I couldn't quite follow the directions.

Can anyone give step-by-step instructions on how to do it on both, Mac and Windows?

share|improve this question
1  
This question has hardly anything to do with applied or theoretical statistics, and I would have voted to close if no (thorough) answers were already given. –  chl Feb 2 '11 at 19:21
1  
@ chl where would these questions go though? I found it quite hard to find references on setting up R, sweave and latex when i started, so thats why i answered. –  richiemorrisroe Feb 2 '11 at 19:30
1  
@richiemorrisroe Well, at least a quick check on SO and Google would be helpful (IMHO). I'm not criticizing the question itself, just the fact that such questions are not really in line with CV FAQ and the other questions here, but I may be wrong. I've upvoted your response as well as @PaulHurleyuk's one, though. I guess this question will be kept alive because of your answers (although there's already a vote to close, which was also the reason of my warning). –  chl Feb 2 '11 at 20:25

4 Answers 4

I use Eclipse / StatEt to produce document with Sweave and LaTex, and find Eclipse perfect as an editing environment. I can recommend the following guides:

I also use MikTex on Windows and find everything works really well once it's setup. There's a few good questions and answers on Stack Overflow as well.

share|improve this answer

For me, I found that Eclipse was overkill for creation of scientific papers. So, for Windows, what i did was the following: Install Miktex 2.8 (? not sure of version). Make sure that you install Miktex into a directory such as C:\Miktex, as Latex hates file paths with spaces in them. Make sure to select the option to install packages on the fly.

Also make sure that R is installed somewhere that Latex can find it i.e. in a path with no spaces. I installed TechNix center as my program to write documents in, but there are many others such as WinEdt, eclipse, texmaker, or indeed Emacs. Now, make sure that you have \usepackage{Sweave} and usepackage{graphicx} in your preamble. As I'm sure you know, you need to put <>= at the start of your R chunk, and end it with @. You will need either the package xtable or Hmisc to convert R objects to a latex format.

I like xtable, but you will probably need to do quite a bit of juggling of objects to get it into a form that xtable will accept (lm outputs, data frames, matrices). When inserting a table make sure to put the results=tex option into your preamble for the code chunk, and if you need a figure, ensure that the fig=TRUE option is also there. You can also only generate one figure per chunk, so just bear that in mind. Something to be very careful with is that the R code is at the extreme left of the page, as if it is enclosed in an environment then it will be ignored (this took me a long time to figure out).

You need to save the file as .Rnw - make sure that whatever tex program you use does not append a .tex after this, as this will cause problems.

Then either run R CMD Sweave foo.Rnw from the command line, or from within R run Sweave("foo.Rnw"). Inevitably it will fail at some point (especially if you haven't done this before) so just debug your .Rnw file, rinse and repeat.

If it is the first time you have done this, it may prove easier to code all the R analyses from within r, and then use print statements to insert them into LaTex. I wouldn't recommend this as a good idea though, as if you discover that your datafile has errors at the end of this procedure (as i did last weekend) then you will need to rerun all of your analyses, which if you could properly from within latex from the beginning, can be avoided.

Also, Sweave computations can take some time, so you may wish to use the R package cacheSweave to save rerunning analyses. Apparently the R package highlight allows for colour coding of R code in documents, but i have not used this.

I've never used latex or R on a Mac, so i will leave that explanation to someone else. Hope this helps.

share|improve this answer

RStudio (rstudio.org) makes things quite easy assuming LaTeX is already installed on your system. There is a PDF button that runs the code through Sweave then runs it through pdflatex and launches a pdf viewer.

share|improve this answer
    
+1 I agree. While it's not a direct answer to GKED's question, I think that users looking for tools like StatET are often the same as those who could benefit from RStudio (i.e., not necessarily the users diving into Emacs/ESS with gusto). While both R Studio and StatET offer similar functionality, RStudio wins in the ease of configuration stakes. –  Jeromy Anglim Jun 5 '11 at 14:21

I installed this suite quite recently and followed the instructions as per instructions here.

There are links to all required software components required. I use MiKTex for all LaTex components.

There are a few pitfalls if you are planning to use 64-bit windows as you will need the additional 64-bit java runtime. This is quite easy to overcome if you go to java.com in a 64-bit IE and verify your installation, it will point you to the 64-bit installer which is otherwise difficult to find.

To avoid mucking around with path variables I simply extracted the eclipse folder in C:\Program Files as this is where java lives and 64-bit R. From here the configuration options in eclipse can easily run automatically and find the appropriate parameters.

I hope this helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.