\HeaderA{read.fortran}{Read fixed-format data}{read.fortran}
\keyword{file}{read.fortran}
\keyword{connection}{read.fortran}
\begin{Description}\relax
Read fixed-format data files using Fortran-style format specifications.
\end{Description}
\begin{Usage}
\begin{verbatim}
read.fortran(file, format, ..., as.is = TRUE, colClasses = NA)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{file}] File or connection to read from
\item[\code{format}] Character vector or list of vectors. See Details below.
\item[\code{...}] Other arguments for \code{read.table}
\item[\code{as.is}] Keep characters as characters?
\item[\code{colClasses}] Variable classes to override defaults. See
\code{\LinkA{read.table}{read.table}} for details.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The format for a field is of one of the following forms: \code{rFl.d},
\code{rDl.d}, \code{rXl}, \code{rAl}, \code{rIl}, where \code{l} is
the number of columns, \code{d} is the number of decimal places, and
\code{r} is the number of repeats. \code{F} and \code{D} are numeric
formats, \code{A} is character, \code{I} is integer, and \code{X}
indicates columns to be skipped. The repeat code \code{r} and decimal
place code \code{d} are always optional. The length code \code{l} is
required except for \code{X} formats when \code{r} is present.

For a single-line record, \code{format} should be a character
vector. For a multiline record it should be a list with a character
vector for each line.

Skipped (\code{X}) columns are not passed to \code{read.table}, so
\code{colClasses}, \code{col.names}, and similar arguments passed to
\code{read.table} should not reference these columns.
\end{Details}
\begin{Value}
A data frame
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{read.fwf}{read.fwf}}, \code{\LinkA{read.csv}{read.csv}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
ff <- tempfile()
cat(file=ff, "123456", "987654", sep="\n")
read.fortran(ff, c("F2.1","F2.0","I2"))
read.fortran(ff, c("2F1.0","2X","2A1"))
unlink(ff)
cat(file=ff, "123456AB", "987654CD", sep="\n")
read.fortran(ff, list(c("2F3.1","A2"), c("3I2","2X")))
unlink(ff)
\end{ExampleCode}
\end{Examples}

