\HeaderA{write\_PACKAGES}{Generate PACKAGES files}{write.Rul.PACKAGES}
\keyword{file}{write\_PACKAGES}
\keyword{utilities}{write\_PACKAGES}
\begin{Description}\relax
Generate \file{PACKAGES} and \file{PACKAGES.gz} files for a
repository of source or Mac/Windows binary packages.
\end{Description}
\begin{Usage}
\begin{verbatim}
write_PACKAGES(dir, fields = NULL,
               type = c("source", "mac.binary", "win.binary"),
               verbose = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{dir}] Character vector describing the location of the repository
(directory including source or binary packages) to generate the
\file{PACKAGES} and \file{PACKAGES.gz} files from and write them to.

\item[\code{fields}] a character vector giving the fields to be used in the
\file{PACKAGES} and \file{PACKAGES.gz} files in addition to the
default ones, or \code{NULL} (default).  The default corresponds to
the fields needed by \code{\LinkA{available.packages}{available.packages}}:
\dQuote{Package}, \dQuote{Bundle}, \dQuote{Priority},
\dQuote{Version}, \dQuote{Depends}, \dQuote{Suggests},
\dQuote{Imports} and \dQuote{Contains}.

\item[\code{type}] Type of packages: currently source \file{.tar.gz} archives, and Mac
or Windows binary (\file{.tgz} or \file{.zip}, respectively)
packages are supported.  Defaults to \code{"win.binary"} on Windows
and to \code{"source"} otherwise.

\item[\code{verbose}] logical.  Should packages be listed as they are
processed?
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{type = "win.binary"} uses \code{\LinkA{unz}{unz}} connections to read
all \file{DESCRIPTION} files contained in the (zipped) binary packages
for Windows in the given directory \code{dir}, and builds
\file{PACKAGES} and \file{PACKAGES.gz} files from these information.
\end{Details}
\begin{Value}
Invisibly returns the number of packages described in the resulting
\file{PACKAGES} and \file{PACKAGES.gz} files.  If 0, no packages were
found and no files were written.
\end{Value}
\begin{Note}\relax
Processing \file{.tar.gz} archives to extract the \file{DESCRIPTION}
files is quite slow.

This function can be useful on other OSes to prepare a repository to
be accessed by Windows machines, so \code{type = "win.binary"} should
work on all OSes.
\end{Note}
\begin{Author}\relax
Uwe Ligges and R-core.
\end{Author}
\begin{SeeAlso}\relax
See \code{\LinkA{read.dcf}{read.dcf}} and \code{\LinkA{write.dcf}{write.dcf}} for reading
\file{DESCRIPTION} files and writing the \file{PACKAGES} and
\file{PACKAGES.gz} files.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Not run: 
write_PACKAGES("c:/myFolder/myRepository")  # on Windows
write_PACKAGES("/pub/RWin/bin/windows/contrib/2.1",
               type="win.binary")  # on Linux
## End(Not run)\end{ExampleCode}
\end{Examples}

