readDataFrame: Reads data from a tabular file

readDataFrameR Documentation

Reads data from a tabular file

Description

Reads data from a tabular file or a set of such files.

Usage

## Default S3 method:
readDataFrame(filename, path=NULL, ...)

Arguments

filename, path

character vector specifying one or more files to be read.

...

Additional arguments passed to either (i) readDataFrame for class TabularTextFile, or (ii) readDataFrame for class TabularTextFileSet, depending on whether one or multiple files are read.

Details

When reading multiple files at once, first each file is read into a data.frame, and then these data.frames are (by default) merged into one data.frame using rbind(). This requires that the same set of columns are read for each file. Which columns to read can be controlled by specifying their names in argument colClasses. To change how the data.frames are merged, use argument combineBy. For more information, follow the help on the above to readDataFrame() help links.

Value

Returns a data.frame.

Author(s)

Henrik Bengtsson

See Also

read.table. For further details, see classes TabularTextFile and TabularTextFileSet.

Examples

path <- system.file("exData/dataSetA,original", package="R.filesets")

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Standard tab-delimited file with header comments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- file.path(path, "fileA,20100112.dat")

# Read all data
df <- readDataFrame(pathname)
print(df)

# Read columns 'x', 'y', and 'char'
df <- readDataFrame(pathname, colClasses=c("(x|y)"="integer", "char"="character"))
print(df)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Tab-delimited file with header comments but
#          also two garbage at the very beginning
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- file.path(path, "fileA,20130116.datx")

# Explicitly skip the two rows
df <- readDataFrame(pathname, skip=2)
print(df)


# Skip until the first data row
df <- readDataFrame(pathname, skip="^x")
print(df)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Tab-delimited file without column header
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- system.file("exData/dataSetB", package="R.filesets")
pathname <- file.path(path, "fileF,noHeader.dat")

# Incorrectly assuming column header
df <- readDataFrame(pathname)
print(df)

# No column header
df <- readDataFrame(pathname, header=FALSE)
print(df)

R.filesets documentation built on May 29, 2024, 9:10 a.m.