开发者

How to make sweave copy generated graphics to a subfolder?

I would love to use some shell script based pdfcrop on all the graphics.pdf cre开发者_开发百科ated from my Sweave report. Hence i'd be nice if all the graphics were stored to a subfolder instead of being dropped where all the latex stuff like .aux .log files (and so on) is located. If I just had to use the crop script on ALL files in a particular directory it would be much easier.

Here's my Sweave chunk:

\begin{figure}[htbp]
  \begin{center}
  <<fig=true,echo=false>>=
  print(mygraph)
  @
\caption{my graph}
\end{center}
\end{figure}

If I run the sweave code mygraph.pdf is stored in the same directory as the report.tex file itself.

Is there a way to store this file in an existing subfolder like /graphics ?


Insert this:

\SweaveOpts{prefix.string=foo/bar}

into your Sweave source file, preferably up the top in the preamble. The above line is taken from the Sweave FAQ, and indicates that the created figures will be stored in the subdirectory (of the directory where the Sweave source is) foo, and each image filename will begin with bar. This, and a whole lot more is discussed in the Sweave FAQ.


Okay RTFM, ran2.

Here's how:

 \SweaveOpts{prefix.string=graphics/report} 

See also: the manual.

graphics is directory and report is a substring you might wanna use. At least you'll find SO better on google :)

EDIT:

For the sake of completeness I'll add my several lines of shell script here:

#!/bin/sh
R CMD Sweave report.Rnw   
for file in `ls graphics`;
do pdfcrop "$file" graphics/"$file"
done
pdflatex report.tex
open report.pdf

Maybe some of you want to use $1 as a directory argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜