\Header{scan}{Read Data Values}
\keyword{file}{scan}
\begin{Usage}
\begin{verbatim}
scan(file="", what= double(0), nmax=-1, n=-1, sep="", skip=0, nlines=0,
         na.strings="NA", flush=FALSE, strip.white=FALSE, quiet=FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{file}] the name of a file to read data values from.  If the
specified file is \texttt{""}, then input is taken from the keyboard
(in this case input can be terminated by a blank line).
\item[\texttt{what}] the type of \texttt{what} gives the type of data to be read.
If \texttt{what} is a list, it is assumed that the lines of the data
file are records each containing \texttt{length(what)} items (``fields'').
\item[\texttt{nmax}] the maximum number of data values to be read, or if
\texttt{what} is a list, the maximum number of records to be read.
If omitted, \texttt{scan} will read to the end of \texttt{file}.
\item[\texttt{n}] the maximum number of data values to be read, defaulting to no limit.
\item[\texttt{sep}] by default, scan expects to read white-space delimited
input fields.  Alternatively, \texttt{sep} can be used to specify a
character which delimits fields.
\item[\texttt{skip}] this many lines of the input file should be skipped
before starting to read data values.
\item[\texttt{nlines}] the maximum number of lines of data to be read.
\item[\texttt{na.strings}] character string, indicating \emph{which} character
fields in the file should translate to missing (\texttt{\Link{NA}}) values.

\item[\texttt{flush}] logical; if \texttt{TRUE}, \texttt{scan} will flush to the end
of the line after reading the last of the fields requested.
This allows putting comments after the last field.

\item[\texttt{strip.white}] vector of logical value(s) corresponding to items in
the \texttt{what} argument. It is used only when \texttt{sep} has been
specified, and allows to strip leading and trailing white space from
\texttt{character} fields (\texttt{numeric} fields are always stripped).

If \texttt{strip.white} is of length 1, it applies to all fields;
otherwise, if \texttt{strip.white[i]} is \texttt{TRUE} \emph{and} the
\texttt{i}-th field is character (because \texttt{what[i]} is), then
the leading and trailing white space from field \texttt{i} is stripped.

\item[\texttt{quiet}] logical; if \texttt{FALSE} (default), scan(.) will print a
line, telling what fields have been read.
\end{ldescription}
\end{Arguments}
\begin{Description}
The value of \texttt{what} can be a list of types, in which case
\texttt{scan} returns a list of vectors with the types given by the
types of the elements in \texttt{what}.  This provides a way of reading
columnar data.

Keyboard entry is terminated by typing a blank line.\end{Description}
\begin{SeeAlso}
\texttt{\Link{read.table}} for more user-friendly reading of data matrices.
\texttt{\Link{write}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
cat("TITEL extra line", "2 3 5 7", "11 13 17", file="ex.data", sep="\n")
pp <- scan("ex.data", skip = 1, quiet= TRUE)
    scan("ex.data", skip = 1)
    scan("ex.data", skip = 1, nlines=1)# only 1 line after the skipped one
str(scan("ex.data", what = list("","",""))) # flush is F -> read "7"
str(scan("ex.data", what = list("","",""), flush = TRUE))
\end{ExampleCode}
\end{Examples}

