read.tsv: Read table-like files into a data frame.

read.tsvR Documentation

Read table-like files into a data frame.

Description

This is a convenience wrapper around read.table for reading tab delimited files. Parsing is the same as with read.table, except the separator is "\t", headers are by default assumed to be present, and strings are automatically read in as strings. You can change these defaults or any other read.table parameter as they are passed through via ..., but you should probably use the actual read.table function if you change sep.

Usage

read.tsv(file, header = TRUE, sep = "\t", stringsAsFactors = FALSE, ...)

Arguments

file

The path to the tab-delimited file.

header

Default is TRUE as most table-like files have headers.

sep

The separator defaults to "\t" for these tab-delimited files.

stringsAsFactors

Set TRUE to convert string columns to factors.

...

Passes other parameters through to read.table

Value

A data frame corresponding to the *.tsv file as specified by the parameters above and the defaults from read.table. See read.table for details.

It is a fatal error if the file does not exist, can not be read, or is empty.

See Also

read.table

Examples

# Create a temp.tsv file to read
tsvFile <- makeTempFile( ext=".tsv", lines= c(
    "name\tval\tok",
    "A\t1\tTRUE",
    "B\t2\tFALSE"
))
read.tsv( tsvFile )
#>   name val    ok
#> 1    A   1  TRUE
#> 2    B   2 FALSE

# A temp.tsv file without a header
tsvFile <- makeTempFile( ext=".tsv", lines= c(
    "A\t1\tTRUE",
    "B\t2\tFALSE"
))
read.tsv( tsvFile )
#>   V1 V2    V3
#> 1  A  1  TRUE
#> 2  B  2 FALSE

# Pass-through setting column names.
tsvFile <- makeTempFile( ext=".tsv", lines= c(
    "A\t1\tTRUE",
    "B\t2\tFALSE"
))
read.tsv( tsvFile, header=FALSE, col.names= c( "name", "val", "ok" ))
#>   name val    ok
#> 1    A   1  TRUE
#> 2    B   2 FALSE


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.