EVOLUTION-MANAGER
Edit File: read.fortran.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Read Fixed-Format Data in a Fortran-like Style</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for read.fortran {utils}"><tr><td>read.fortran {utils}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Read Fixed-Format Data in a Fortran-like Style</h2> <h3>Description</h3> <p>Read fixed-format data files using Fortran-style format specifications. </p> <h3>Usage</h3> <pre> read.fortran(file, format, ..., as.is = TRUE, colClasses = NA) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>file</code></td> <td> <p>File or <a href="../../base/html/connections.html">connection</a> to read from.</p> </td></tr> <tr valign="top"><td><code>format</code></td> <td> <p>Character vector or list of vectors. See ‘Details’ below.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Other arguments for <code><a href="read.fwf.html">read.fwf</a></code>.</p> </td></tr> <tr valign="top"><td><code>as.is</code></td> <td> <p>Keep characters as characters?</p> </td></tr> <tr valign="top"><td><code>colClasses</code></td> <td> <p>Variable classes to override defaults. See <code><a href="read.table.html">read.table</a></code> for details.</p> </td></tr> </table> <h3>Details</h3> <p>The format for a field is of one of the following forms: <code>rFl.d</code>, <code>rDl.d</code>, <code>rXl</code>, <code>rAl</code>, <code>rIl</code>, where <code>l</code> is the number of columns, <code>d</code> is the number of decimal places, and <code>r</code> is the number of repeats. <code>F</code> and <code>D</code> are numeric formats, <code>A</code> is character, <code>I</code> is integer, and <code>X</code> indicates columns to be skipped. The repeat code <code>r</code> and decimal place code <code>d</code> are always optional. The length code <code>l</code> is required except for <code>X</code> formats when <code>r</code> is present. </p> <p>For a single-line record, <code>format</code> should be a character vector. For a multiline record it should be a list with a character vector for each line. </p> <p>Skipped (<code>X</code>) columns are not passed to <code>read.fwf</code>, so <code>colClasses</code>, <code>col.names</code>, and similar arguments passed to <code>read.fwf</code> should not reference these columns. </p> <h3>Value</h3> <p>A data frame </p> <h3>Note</h3> <p><code>read.fortran</code> does not use actual Fortran input routines, so the formats are at best rough approximations to the Fortran ones. In particular, specifying <code>d > 0</code> in the <code>F</code> or <code>D</code> format will shift the decimal <code>d</code> places to the left, even if it is explicitly specified in the input file. </p> <h3>See Also</h3> <p><code><a href="read.fwf.html">read.fwf</a></code>, <code><a href="read.table.html">read.table</a></code>, <code><a href="read.table.html">read.csv</a></code></p> <h3>Examples</h3> <pre> 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) # Note that the first number is read differently than Fortran would # read it: cat(file = ff, "12.3456", "1234567", sep = "\n") read.fortran(ff, "F7.4") unlink(ff) </pre> <hr /><div style="text-align: center;">[Package <em>utils</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>