\HeaderA{write.foreign}{Write Text Files and Code to Read Them}{write.foreign}
\keyword{file}{write.foreign}
\begin{Description}\relax
This function exports data frames to other statistical packages by
writing the data as free-format text and writing a separate file of
instructions for the other package to read the data.
\end{Description}
\begin{Usage}
\begin{verbatim}
write.foreign(df, datafile, codefile, package = c("SPSS","Stata","SAS"), ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{df}] A data frame
\item[\code{datafile}] Name of file for data output
\item[\code{codefile}] Name of file for code output
\item[\code{package}] Name of package
\item[\code{...}] Other arguments for the individual \code{writeForeign} functions
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The work for this function is done by
\code{foreign:::writeForeignStata}, \code{foreign:::writeForeignSAS} and
\code{foreign:::writeForeignSPSS}. To add support for another package,
eg Systat, create a function \code{writeForeignSystat} with the same first
three arguments as \code{write.foreign}. This will be called from
\code{write.foreign} when \code{package="Systat"}.

For \code{package="SAS"} there is an optional argument \code{dataname="rdata"}
taking a string that will be the SAS data set name.
\end{Details}
\begin{Value}
None
\end{Value}
\begin{Author}\relax
Thomas Lumley
\end{Author}
\begin{Examples}
\begin{ExampleCode}
## Not run: 
datafile<-tempfile()
codefile<-tempfile()
write.foreign(esoph,datafile,codefile,package="SPSS")
file.show(datafile)
file.show(codefile)
unlink(datafile)
unlink(codefile)
## End(Not run)
\end{ExampleCode}
\end{Examples}

