Learn R Programming

mosaic (version 0.4-1)

read.file: Read data files

Description

A wrapper around read.table, read.csv, and load to unify and simply reading data from files.

Usage

read.file(file, header = T,
    na.strings = c("NA", "", ".", "na", "-"),
    comment.char = "#", ...)

Arguments

file
character: The name of the file which the data are to be read from. This may also be a complete URL or a path to a compressed file. If it does not contain an absolute path, the file name is relative to the current working directory, getwd(
header
logical; For .txt and .csv files, this indicates whether the first line of the file includes variables names.
na.strings
character: strings that indicate missing data.
comment.char
character: a character vector of length one containing a single character or an empty string. Use "" to turn off the interpretation of comments altogether.
...
additional arguments passed on to read.table, read.csv, or load.

Value

  • A data frame, unless file ends in .Rdata, in which case arbitrary objects may be loaded and a character vector holding the names of the loaded objects is returned invisibly.

Details

read.file uses the file extension to determine how to read data from the file. If file ends in .Rdata, then load is used to load the file. If file ends in .csv, then read.csv is used. Otherwise, read.table is used.

See Also

read.table, read.csv, load.