\HeaderA{sys.source}{Parse and Evaluate Expressions from a File}{sys.source}
\keyword{file}{sys.source}
\keyword{utilities}{sys.source}
\begin{Description}\relax
Parses expressions in the given file, and then successively evaluates
them in the specified environment.
\end{Description}
\begin{Usage}
\begin{verbatim}
sys.source(file, envir = baseenv(), chdir = FALSE,
           keep.source = getOption("keep.source.pkgs"))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{file}] a character string naming the file to be read from
\item[\code{envir}] an \R{} object specifying the environment in which the
expressions are to be evaluated.  May also be a list or an integer.
The default value \code{NULL} corresponds to evaluation in the base
environment.  This is probably not what you want; you should
typically supply an explicit \code{envir} argument.
\item[\code{chdir}] logical; if \code{TRUE}, the \R{} working directory is
changed to the directory containing \code{file} for evaluating.
\item[\code{keep.source}] logical.  If \code{TRUE}, functions keep
their source including comments, see
\code{\LinkA{options}{options}(keep.source = *)} for more details.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For large files, \code{keep.source = FALSE} may save quite a bit of
memory.
In order for the code being evaluated to use the correct environment
(for example, in global assignments), source code in packages should
call
\code{\LinkA{topenv}{topenv}()}, which will return the name space, if any, the
environment set up by \code{sys.source}, or the global environment
if a saved image is being used.
\end{Details}
\begin{SeeAlso}\relax
\code{\LinkA{source}{source}}, and \code{\LinkA{library}{library}} which uses
\code{sys.source}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## a simple way to put some objects in an environment high on the search path
tmp <- tempfile()
writeLines("aaa <- pi", tmp)
env <- attach(NULL, name = "myenv")
sys.source(tmp, env)
unlink(tmp)
search()
aaa
detach("myenv")
\end{ExampleCode}
\end{Examples}

