read_table() and read_table2() are designed to read the type of textual data where each column is separated by one (or more) columns of space. read_table2() is like read.table(), it allows any number of whitespace characters between columns, and the lines can be of different lengths. read_table() is more strict, each line must be the same length, and each field is in the same position in every line. It first finds empty columns and then parses like a fixed width file. spec_table() and spec_table2() return the column specifications rather than a data frame.

read_table(file, col_names = TRUE, col_types = NULL,
locale = default_locale(), na = "NA", skip = 0, n_max = Inf,
guess_max = min(n_max, 1000), progress = show_progress(), comment = "")

read_table2(file, col_names = TRUE, col_types = NULL,
locale = default_locale(), na = "NA", skip = 0, n_max = Inf,
guess_max = min(n_max, 1000), progress = show_progress(), comment = "")

## Arguments

file Either a path to a file, a connection, or literal data (either a single string or a raw vector). Files ending in .gz, .bz2, .xz, or .zip will be automatically uncompressed. Files starting with http://, https://, ftp://, or ftps:// will be automatically downloaded. Remote gz files can also be automatically downloaded and decompressed. Literal data is most useful for examples and tests. It must contain at least one new line to be recognised as data (instead of a path) or be a vector of greater than length 1. Using a value of clipboard() will read from the system clipboard. Either TRUE, FALSE or a character vector of column names. If TRUE, the first row of the input will be used as the column names, and will not be included in the data frame. If FALSE, column names will be generated automatically: X1, X2, X3 etc. If col_names is a character vector, the values will be used as the names of the columns, and the first row of the input will be read into the first row of the output data frame. Missing (NA) column names will generate a warning, and be filled in with dummy names X1, X2 etc. Duplicate column names will generate a warning and be made unique with a numeric prefix. One of NULL, a cols() specification, or a string. See vignette("readr") for more details. If NULL, all column types will be imputed from the first 1000 rows on the input. This is convenient (and fast), but not robust. If the imputation fails, you'll need to supply the correct types yourself. If a column specification created by cols(), it must contain one column specification for each column. If you only want to read a subset of the columns, use cols_only(). Alternatively, you can use a compact string representation where each character represents one column: c = character, i = integer, n = number, d = double, l = logical, D = date, T = date time, t = time, ? = guess, or _/- to skip the column. The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale() to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names. Character vector of strings to use for missing values. Set this option to character() to indicate no missing values. Number of lines to skip before reading data. Maximum number of records to read. Maximum number of records to use for guessing column types. Display a progress bar? By default it will only display in an interactive session and not while knitting a document. The display is updated every 50,000 values and will only display if estimated reading time is 5 seconds or more. The automatic progress bar can be disabled by setting option readr.show_progress to FALSE. A string used to identify comments. Any text after the comment characters will be silently ignored.

read_fwf() to read fixed width files where each column is not separated by whitespace. read_fwf() is also useful for reading tabular data with non-standard formatting.

## Examples

# One corner from http://www.masseyratings.com/cf/compare.htm
cat(read_file(massey))#> UCC PAY LAZ KPK  RT   COF BIH DII ENG ACU Rank Team            Conf
#>   1   1   1   1   1     1   1   1   1   1    1 Ohio St          B10
#>   2   2   2   2   2     2   2   2   4   2    2 Oregon           P12
#>   3   4   3   4   3     4   3   4   2   3    3 Alabama          SEC
#>   4   3   4   3   4     3   5   3   3   4    4 TCU              B12
#>   6   6   6   5   5     7   6   5   6  11    5 Michigan St      B10
#>   7   7   7   6   7     6  11   8   7   8    6 Georgia          SEC
#>   5   5   5   7   6     8   4   6   5   5    7 Florida St       ACC
#>   8   8   9   9  10     5   7   7  10   7    8 Baylor           B12
#>   9  11   8  13  11    11  12   9  14   9    9 Georgia Tech     ACC
#>  13  10  13  11   8     9  10  11   9  10   10 Mississippi      SEC read_table(massey)#> Parsed with column specification:
#> cols(
#>   UCC = col_double(),
#>   PAY = col_double(),
#>   LAZ = col_double(),
#>   KPK = col_double(),
#>   RT = col_double(),
#>   COF = col_double(),
#>   BIH = col_double(),
#>   DII = col_double(),
#>   ENG = col_double(),
#>   ACU = col_double(),
#>   Rank = col_double(),
#>   Team = col_character(),
#>   Conf = col_character()
#> )#> # A tibble: 10 x 13
#>      UCC   PAY   LAZ   KPK    RT   COF   BIH   DII   ENG   ACU  Rank Team
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#>  1  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00 Ohio St
#>  2  2.00  2.00  2.00  2.00  2.00  2.00  2.00  2.00  4.00  2.00  2.00 Oregon
#>  3  3.00  4.00  3.00  4.00  3.00  4.00  3.00  4.00  2.00  3.00  3.00 Alabama
#>  4  4.00  3.00  4.00  3.00  4.00  3.00  5.00  3.00  3.00  4.00  4.00 TCU
#>  5  6.00  6.00  6.00  5.00  5.00  7.00  6.00  5.00  6.00 11.0   5.00 Michigan …
#>  6  7.00  7.00  7.00  6.00  7.00  6.00 11.0   8.00  7.00  8.00  6.00 Georgia
#>  7  5.00  5.00  5.00  7.00  6.00  8.00  4.00  6.00  5.00  5.00  7.00 Florida St
#>  8  8.00  8.00  9.00  9.00 10.0   5.00  7.00  7.00 10.0   7.00  8.00 Baylor
#>  9  9.00 11.0   8.00 13.0  11.0  11.0  12.0   9.00 14.0   9.00  9.00 Georgia T…
#> 10 13.0  10.0  13.0  11.0   8.00  9.00 10.0  11.0   9.00 10.0  10.0  Mississip…
#> # ... with 1 more variable: Conf <chr>
# Sample of 1978 fuel economy data from
cat(read_file(epa))#> ALFA ROMEO                                                                     ALFA ROMEO           78010003
#> ALFETTA                              03  81  8    74  7   89  9                ALFETTA              78010053
#> SPIDER 2000                          01                                        SPIDER 2000          78010103
#> AMC                                                                            AMC                  78020002
#> GREMLIN                              03  79  9                    79  9        GREMLIN              78020053
#> PACER                                04  89 11                    89 11        PACER                78020103
#> PACER WAGON                          07  90 26    91 26                        PACER WAGON          78020153
#> CONCORD                              04  88 12    90 11   90 11   83 16        CONCORD              78020203
#> CONCORD WAGON                        07  91 30            91 30                CONCORD WAGON        78020253
#> ASTON MARTIN                                                                   ASTON MARTIN         78040002
#> ASTON MARTIN                                                                   ASTON MARTIN         78040053
#> AUDI                                                                           AUDI                 78050002
#> FOX                                  03  84 11    84 11   84 11                FOX                  78050053
#> FOX WAGON                            07  83 40            83 40                FOX WAGON            78050103
#> 5000                                 04  90 15            90 15                5000                 78050153
#> AVANTI                                                                         AVANTI               78065002
#> AVANTI II                            02  75  8    75  8                        AVANTI II            78065053read_table(epa, col_names = FALSE)#> Parsed with column specification:
#> cols(
#>   X1 = col_character(),
#>   X2 = col_character(),
#>   X3 = col_double(),
#>   X4 = col_double(),
#>   X5 = col_double(),
#>   X6 = col_double(),
#>   X7 = col_double(),
#>   X8 = col_double(),
#>   X9 = col_double(),
#>   X10 = col_double(),
#>   X11 = col_character(),
#>   X12 = col_double()
#> )#> # A tibble: 20 x 12
#>    X1      X2       X3    X4    X5    X6    X7    X8    X9   X10 X11        X12
#>    <chr>   <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>    <dbl>
#>  1 ALFA R… ""     NA   NA     NA   NA     NA   NA     NA   NA    ALFA R… 7.80e⁷
#>  2 ALFETTA 03     81.0  8.00  74.0  7.00  89.0  9.00  NA   NA    ALFETTA 7.80e⁷
#>  3 SPIDER… 01     NA   NA     NA   NA     NA   NA     NA   NA    SPIDER… 7.80e⁷
#>  4 AMC     ""     NA   NA     NA   NA     NA   NA     NA   NA    AMC     7.80e⁷
#>  5 GREMLIN 03     79.0  9.00  NA   NA     NA   NA     79.0  9.00 GREMLIN 7.80e⁷
#>  6 PACER   04     89.0 11.0   NA   NA     NA   NA     89.0 11.0  PACER   7.80e⁷
#>  7 PACER … 07     90.0 26.0   91.0 26.0   NA   NA     NA   NA    PACER … 7.80e⁷
#>  8 CONCORD 04     88.0 12.0   90.0 11.0   90.0 11.0   83.0 16.0  CONCORD 7.80e⁷
#>  9 CONCOR… 07     91.0 30.0   NA   NA     91.0 30.0   NA   NA    CONCOR… 7.80e⁷
#> 10 MATADO… 05     97.0 14.0   97.0 14.0   NA   NA     NA   NA    MATADO… 7.80e⁷
#> 11 MATADO… 06    110   20.0   NA   NA    110   20.0   NA   NA    MATADO… 7.80e⁷
#> 12 MATADO… 09    112   50.0   NA   NA    112   50.0   NA   NA    MATADO… 7.80e⁷
#> 13 ASTON … ""     NA   NA     NA   NA     NA   NA     NA   NA    ASTON … 7.80e⁷
#> 14 ASTON … ""     NA   NA     NA   NA     NA   NA     NA   NA    ASTON … 7.80e⁷
#> 15 AUDI    ""     NA   NA     NA   NA     NA   NA     NA   NA    AUDI    7.81e⁷
#> 16 FOX     03     84.0 11.0   84.0 11.0   84.0 11.0   NA   NA    FOX     7.81e⁷
#> 17 FOX WA… 07     83.0 40.0   NA   NA     83.0 40.0   NA   NA    FOX WA… 7.81e⁷
#> 18 5000    04     90.0 15.0   NA   NA     90.0 15.0   NA   NA    5000    7.81e⁷
#> 19 AVANTI  ""     NA   NA     NA   NA     NA   NA     NA   NA    AVANTI  7.81e⁷
#> 20 AVANTI… 02     75.0  8.00  75.0  8.00  NA   NA     NA   NA    AVANTI… 7.81e⁷