\HeaderA{dput}{Write an Object to a File or Recreate it}{dput}
\aliasA{dget}{dput}{dget}
\keyword{file}{dput}
\keyword{programming}{dput}
\keyword{connection}{dput}
\begin{Description}\relax
Writes an ASCII text representation of an \R{} object to a file
or connection, or uses one to recreate the object.
\end{Description}
\begin{Usage}
\begin{verbatim}
dput(x, file = "",
     control = c("keepNA", "keepInteger", "showAttributes"))

dget(file)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an object.
\item[\code{file}] either a character string naming a file or a
connection. \code{""} indicates output to the console.
\item[\code{control}] character vector indicating deparsing options.
See \code{\LinkA{.deparseOpts}{.deparseOpts}} for their description.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{dput} opens \code{file} and deparses the object \code{x} into
that file.  The object name is not written (unlike \code{dump}).
If \code{x} is a function the associated environment is stripped.
Hence scoping information can be lost.

Deparsing an object is difficult, and not always possible.  With the
default \code{control}, \code{dput()} attempts to deparse in a way
that is readable, but for more complex or unusual objects (see
\code{\LinkA{dump}{dump}}, not likely
to be parsed as identical to the original.  Use \code{control = "all"}
for the most complete deparsing; use \code{control = NULL} for the
simplest deparsing, not even including attributes.

\code{dput} will warn if fewer characters were written to a file than
expected, which may indicate a full or corrupt file system.

To display saved source rather than deparsing the internal representation 
include \code{"useSource"} in \code{control}.  \R{} currently saves
source only for function definitions.
\end{Details}
\begin{Value}
For \code{dput}, the first argument invisibly.

For \code{dget}, the object created.
\end{Value}
\begin{Note}\relax
To avoid the risk of a source attribute out of sync with the actual
function definition, the source attribute of a function will never 
be written as an attribute.
\end{Note}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{deparse}{deparse}}, \code{\LinkA{dump}{dump}}, \code{\LinkA{write}{write}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Write an ASCII version of mean to the file "foo"
dput(mean, "foo")
## And read it back into 'bar'
bar <- dget("foo")
unlink("foo")
## Create a function with comments
baz <- function(x) {
  # Subtract from one
  1-x
}
## and display it
dput(baz)
## and now display the saved source
dput(baz, control = "useSource")
\end{ExampleCode}
\end{Examples}

