[R] Understanding the workflow between sweave, R and Latex
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Sep 30 14:41:11 CEST 2011
On 30/09/2011 8:03 AM, syrvn wrote:
> Let's say I have written the following tiny .Rnw file:
>
> _________________________________________
> \documentclass{article}
>
> \usepackage[utf8]{inputenc}
>
> \usepackage{Sweave}
>
> \usepackage{tikz}
>
> \usepackage{pgf}
>
> \begin{document}
>
> <<>>=
>
> sessionInfo()
>
> @
>
> \end{document}
> _________________________________________
>
> I then can go to R and use sweave to translate the .Rnw file into a .tex
> file
>
> Once this is done the latex interpreter can be called and because I used
>
> \usepackage{Sweave} Latex knows how to handle the sweave specific code tags.
>
> When I first did this procedure I got the commong error that the Sweave.sty
> file could
>
> not be found. I googled and could solve the problem by typing the following
> command
>
> into the Mac OS Terminal:
>
> _________________________________________
> mkdir -p ~/Library/texmf/tex/latex
>
> cd ~/Library/texmf/tex/latex
>
> ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave
> _________________________________________
>
> What I don't understand now is how does the latex package
> \usepackage{Sweave} know that it
>
> has to look at ~/Library/texmf/tex/latex to find the symbolic link to the
> Sweave.sty file?
>
> What happens if I change the following line:
>
> ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave
>
> to
>
> ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave_Link
>
> In the .Rnw file do I have to use then \usepackage{Sweave_Link}?
No. You need to read up on LaTeX documentation, and particularly on the
documentation for your particular implementation, to find out how it
searches for packages, but in general it is looking for the file named
Sweave.sty, and the directory containing it could be named anything.
As an aside, I don't recommend the workflow you describe: it's very
slow and cumbersome. It's much better to tell your text editor how to
run both Sweave and Latex in one command. In the upcoming release of R
2.14.0, this is a single command: R CMD Sweave --pdf. In earlier
releases, it's only slightly more complicated: you need to process the
Rnw to tex, then the tex to pdf using pdflatex or similar. (You can do
more elaborate conversions using my patchDVI package; it's on R-forge,
here: https://r-forge.r-project.org/R/?group_id=233).
Duncan Murdoch
More information about the R-help
mailing list