\HeaderA{savepng}{Save the contents of the current graphics device to a file}{savepng}
\aliasA{saveeps}{savepng}{saveeps}
\aliasA{savepdf}{savepng}{savepdf}
\aliasA{savetiff}{savepng}{savetiff}
\keyword{programming}{savepng}
\keyword{error}{savepng}
\begin{Description}\relax
Save the contents of the current graphics device to file
\end{Description}
\begin{Usage}
\begin{verbatim}
  savepdf(fn, dir, width=6, asp=1)
  saveeps(fn, dir, width=6, asp=1) 
  savepng(fn, dir, width=480, asp=1)
  savetiff(fn, dir, density=360, keeppdf=TRUE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fn}] character: name of the output file (without extension). 
An extension \code{.pdf}, \code{.eps}, \code{.png}, or \code{.tiff}
will be added automatically.
\item[\code{dir}] character: directory to which the file should be written.
\item[\code{width}] numeric: width of the image in pixels (png) or inches
(pdf, eps).
\item[\code{asp}] numeric: aspect ratio; height=width*asp.
\item[\code{density}] pixels per inch (see Details).
\item[\code{keeppdf}] Should the intermediate PDF file (see Details)
be kept? If \code{FALSE}, it is deleted before the function
returns.
\item[\code{...}] Further arguments that are passed on to \code{savepdf}
(see Details).
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The functions are called for their side effect, writing a
graphics file.

\code{savepdf}, \code{savepng}, and \code{saveeps} use the
devices \code{\LinkA{pdf}{pdf}}, \code{\LinkA{png}{png}}, and
\code{\LinkA{postscript}{postscript}}, respectively.

There is currently no TIFF device for R, so \code{savetiff}
works differently. It relies on the external tool \code{convert} from
the ImageMagick software package. First, \code{savetiff} produces
a PDF files with \code{savepdf}, then uses \code{\LinkA{system}{system}} to
invoke \code{convert} with the parameter \code{density}.
\code{savetiff} does \bold{not} check for the existence of 
\code{convert} or the success of the system call, and returns silently
no matter what.
\end{Details}
\begin{Value}
Character: name of the file that was written.
\end{Value}
\begin{Author}\relax
Wolfgang Huber \url{http://www.dkfz.de/abt0840/whuber}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{dev.copy}{dev.copy}}, \code{\LinkA{pdf}{pdf}}, \code{\LinkA{png}{png}},
\code{\LinkA{postscript}{postscript}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x = seq(0, 20*pi, len=1000)
  plot(x*sin(x), x*cos(x), type="l")

  try({   ## on some machines, some of the devices may not be available
    c(
      savepdf("spiral", dir=tempdir()),
      savepng("spiral", dir=tempdir()),
      saveeps("spiral", dir=tempdir()),
      savetiff("spiral", dir=tempdir())
     )
  })    
\end{ExampleCode}
\end{Examples}

