On Fri, Mar 13, 2009 at 12:17 PM, Duncan Murdoch <murd...@stats.uwo.ca> wrote:
> On 3/13/2009 12:07 PM, Ptit_Bleu wrote:
>>
>> Thanks Dieter for the link.

>
> You can use \includegraphics explicitly yourself, and avoid the automatic
> code generated by Sweave.  For example,
>
> <<testfn, fig=true, include=false>>=
> curve(f, from = 1, to = 5)
> @
>
> That generates the figure, but doesn't include it; then
>
> \begin{figure}
> \begin{center}
> \includegraphics{-testfn}
> \caption{The function $f(x) = |x-3.5| + (x-2)^2$.\label{fig:testfn}}
> \end{center}
> \end{figure}
>
> will do the include.  You need to name the chunk that creates the figure for
> this to be workable, and if you have set a prefix in your SweaveOpts, you
> need to use it in the \includegraphics call.  (Actually I forget if the
> hyphen is needed; I stripped off a prefix from the real example to show you
> this.)
>
> Duncan Murdoch
>

Dear Duncan:

Thanks for the tip. This is very useful to me.

Just to clear up the filename question, I worked up an example for
testing.  For me it is necessary to include the name of the Rnw/tex
file as a prefix in the includegraphics command.  Maybe that's just
me, or Ubuntu, or TexLive2007.

Here is a working file SweaveExample.Rnw.  In order to make this work,
you see the figure names in includegraphics.

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\usepackage{babel}

\begin{document}
<<testfn, fig=true, include=false>>=
curve(sin, from = 1, to = 5)
@

<<testfn2, fig=true, include=false>>=
curve(sin, from = 1, to = 5)
@

%
\begin{figure}
\caption{My Figure}
\includegraphics{SweaveExample-testfn}
\end{figure}

%%works without float too:
\includegraphics{SweaveExample-testfn2}
\end{document}


-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to