read.fortran              package:utils              R Documentation

_R_e_a_d _f_i_x_e_d-_f_o_r_m_a_t _d_a_t_a

_D_e_s_c_r_i_p_t_i_o_n:

     Read fixed-format data files using Fortran-style format
     specifications.

_U_s_a_g_e:

     read.fortran(file, format, ..., as.is = TRUE, colClasses = NA)

_A_r_g_u_m_e_n_t_s:

    file: File or connection to read from

  format: Character vector or list of vectors. See Details below.

     ...: Other arguments for 'read.table'

   as.is: Keep characters as characters?

colClasses: Variable classes to override defaults. See 'read.table' for
          details.

_D_e_t_a_i_l_s:

     The format for a field is of one of the following forms: 'rFl.d',
     'rDl.d', 'rXl', 'rAl', 'rIl', where 'l' is the number of columns,
     'd' is the number of decimal places, and 'r' is the number of
     repeats. 'F' and 'D' are numeric formats, 'A' is character, 'I' is
     integer, and 'X' indicates columns to be skipped. The repeat code
     'r' and decimal place code 'd' are always optional. The length
     code 'l' is required except for 'X' formats when 'r' is present.

     For a single-line record, 'format' should be a character vector.
     For a multiline record it should be a list with a character vector
     for each line.

     Skipped ('X') columns are not passed to 'read.table', so
     'colClasses', 'col.names', and similar arguments passed to
     'read.table' should not reference these columns.

_V_a_l_u_e:

     A data frame

_S_e_e _A_l_s_o:

     'read.fwf', 'read.csv'

_E_x_a_m_p_l_e_s:

     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)

