GeneralR and Latex

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
karisalk
Posts: 12
Joined: Wed Jul 21, 2010 12:59 pm

R and Latex

Post by karisalk »

Hi,One can integrate R(a statistical software) and Latex using the function Sweave in R. I have failed to produce a document using these two software. If there is anybody who has mastered the two, may you help me.
thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Re: R and Latex

Post by albart »

Hi Karisalk,

you should consider to show us a small example of your .Rnw file in order to be able to help you. I have used the Sweave->Latex route many times and, when I did not make mistakes, never had problems.

So, where does you problem occur:

1: in R, by running the Sweave function
2: when compiling the .tex file to a dvi or pdf

Regards,

Albart
karisalk
Posts: 12
Joined: Wed Jul 21, 2010 12:59 pm

Re: R and Latex

Post by karisalk »

I dont know how to use the Sweave Function in R.
I dont Know what is the so called .Rnw,.sty, etc files and how to create them.
I tried the following example from some where,I copied it and ran it on Miktex:

\documentclass[a4paper]{article}
\begin{document}
<<>>=
data(airquality)
library(ctest)
kruskal.test(Ozone ~ Month, data = airquality)
@
\begin{center}
<<fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
@
\end{center}
\end{document}

I dont get the PDF with the R codes.
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

R and Latex

Post by albart »

Hi,

then it is good to learn about these files. You should place the code in a file: file.Rnw and the run the Sweave function in R on this file:

Code: Select all

Sweave('file.Rnw')
. This will produce the file file.tex, on which you can then run latex using Miktex: pdflatex file.tex for example.

I would encourage you to read the documentation of Sweave at http://www.stat.auckland.ac.nz/~stat782 ... manual.pdf.

Albart
karisalk
Posts: 12
Joined: Wed Jul 21, 2010 12:59 pm

Re: R and Latex

Post by karisalk »

I wrote the latex document and saved it in my documents as myfile.Rnw
When I sweave in R,

> Sweave("myfile.Rnw")

I get the following error;
Writing to file myfile.tex
Processing code chunks ...
Error in SweaveReadFile(file, syntax) :
no Sweave file with name 'myfile.Rnw' found

What could be the correct saving because that is what I think is the mistake that I cannot locate the file "myfile.Rnw" or what should I do?
Thank you

Karisa,l.k.
karisalk
Posts: 12
Joined: Wed Jul 21, 2010 12:59 pm

Re: R and Latex

Post by karisalk »

Thank you. It has just worked out well after several failures. It is just like learning how to ride a bicycle, after a little wobling it is piece of cake!! Thank you once again.
Karisa,l.k.
Post Reply