Workflow between latex and R threaded

Trying to write my second latex file

\documentclass{article} \title{simple Sweave script} \usepackage{/Users/Brenden/Documents/R/R-2.15.1/share/texmf/tex/latex/Sweave} \begin{document} \maketitle This is a simple script to demonstrate Sweave. Let's begin by generating some results <<>>= x=rnorm(30) y=rnorm(30) mean(x) cor(x,y) @ and follow that up with some random text \end{document} 

File saved with .Rnw as an extension. Then I could use Sweave under R to convert the file to tex. Then I run pdflatex under cmd to get the .pdf file. R is stored in the / Users / Brenden / Documents section. MiKTex is stored in the / Users / Brenden / Desktop section.

They say that usually the line "usepackage" is not needed, because when I run Sweave under R, the line "usepackage {Sweave}" will be added to the tex file, which is stored in the / Users / Brenden / Documents section. However, if I do not put the userpackage line when I run pdflatex under cmd (either under / Documents or / Desktop), I get a message that says: "Sweave.sty not found". So I overcame this problem by always adding a usepackage line with a detailed path to help get around the problem. Although the "Sweave.sty not found" problem is bypassed, I notice that when I run pdflatex under cmd, I got an answer

 LaTeX Warning: You have requested package '/Users/Brenden/Documents/R/R- 2.15.1/share/texmf/tex/latex/Sweave', but the package provides "Sweave'. 

Then it runs through several .sty files under MiKTex

 (C:\Users\Brenden\Desktop\MiKTex\tex\latex\base\ifthen.sty) (C:\Users\Brenden\Desktop\MiKTex\tex\latex\graphics\graphicx.sty) (C:\Users\Brenden\Desktop\MiKTex\tex\latex\graphics\keyval.sty) (C:\Users\Brenden\Desktop\MiKTex\tex\latex\graphics\graphics.sty) (C:\Users\Brenden\Desktop\MiKTex\tex\latex\graphics\trig.sty) ... 

to end up creating .pdf

From another post in Stackoverflow it says: "This path is set automatically when LaTeX is installed, this is your personal texmf tree, and you can put any style or class files that you want LaTeX to find. It doesn't matter, it recursively searches them for Sweave.sty" . However, for me, obviously, my MiKTex could not find Sweave.sty unless I showed the way. And even with a path, LaTex still gives me a warning. Can someone explain to me where I screwed up (during the installation of MiKTex, maybe?), So that I can help MiKtex find its way to Sweave without specifying a path?

Thanks.

+6
source share
4 answers

The MiKTeX settings program has a tab called "Roots". This is where you can indicate where additional .sty files can be found. In your case, I believe that you need to add C:\Users\Brenden\Documents\R\R-2.15.1\share\texmf as an additional root. In this case, any of the TeX programs will be able to find Sweave.sty , whether it is executed from within R or from the command line.

+7
source

It is annoying that he is always distracted by such little devils (new texmf tree concept, endless environment variables TEXINPUTS , SWEAVE_STYLEPATH_DEFAULT , ...). You will not worry about LaTeX packages if you use knitr , and if you like the Sweave style, you can just put render_sweave() in the document, for example:

 \documentclass{article} \title{simple Sweave script} <<setup, include=FALSE>>= render_sweave() @ \begin{document} \maketitle This is a simple script to demonstrate Sweave. Let's begin by generating some results <<>>= x=rnorm(30) y=rnorm(30) mean(x) cor(x,y) @ and follow that up with some random text \end{document} 

Save it as, say, test.Rnw and compile it with

 library(knitr); knit('test.Rnw') # or knit2pdf('test.Rnw') 

And I think you are probably better off without render_sweave() (i.e. use the default LaTeX style in knitr ).

+6
source

I suspect that the path mentioned in another post is the path to your personal texmf tree that is not in Sweave. One option is to move it to your personal texmf tree, but the usual method, it seems to me, is to run pdflatex from R, for example:

 texi2dvi("foo.tex", pdf = TRUE) 

I think you can also add sweave automatically by adding

 export SWEAVE_STYLEPATH_DEFAULT="TRUE" 

to your .bashrc or whatever the equivalent will be on your system.

+4
source

At the R CMD command line, R CMD sets up an environment with variables suitable for running R, such as on Windows

 C:\Users\mtmorgan> "c:\Program Files\R\R-2.15.1\bin\R" CMD set 

includes (this is not found if one type is set on the command line)

 TEXINPUTS=.;c:/PROGRA~1/R/R-215~1/.1/share/texmf/tex/latex; 

and therefore

 C:\Users\mtmorgan> "c:\Program Files\R\R-2.15.1\bin\R" CMD pdflatex myfile.tex 

will find Sweave.sty. Alternatively, tools::texi2dvi can be called from R.

+2
source

All Articles