Using Sweave, how can I reliably get .PNG figures instead of .EPS or .PDF figures?

I have tried to set the options in the preamble:

\SweaveOpts{keep.source=TRUE, eps=FALSE, pdf=FALSE, png=TRUE}

but this does not reliably produce only .png (or indeed any!) figures. I say 'reliably' as I have been successful previously in getting the .png figures, but having made some modifications to my document (alas, unscientifically) Sweave no longer produces any figures.

-

There is no option for automatic PNG output in the official Sweave distribution. The only options are PDF or EPS-- you are not seeing output because you have turned both of those off.

You can use whatever output device you want by forgoing the use of fig=TRUE and writing code that looks like:

\begin{figure}

\caption{Some silly plot.}
\label{fig:sillyPlot}

<<fig1>>=
png( 'fig1.png' )

# Plotting stuff.

dev.off() # <- very very important
@
\includegraphics{fig1}

\end{figure}


\begin{figure}

\caption{Some silly plot.}
\label{fig:sillyPlot}

<<fig1,fig=TRUE>>=

# Plotting stuff.

@

\end{figure}


The fig=TRUE option really just saves some typing by freeing you from opening the device, closing it and then inserting the \includegraphics{} command for LaTeX. If you really want fig=TRUE to support PNG output you will have to roll your own modified Sweave driver or use this one created by Thibaut Jombart.

-