db.read | R Documentation |
Reads a set of delimited text files supposed to form a relational data base
db.read(dir = ".", ext = "tsv", sep = "\t", ...)
dir |
Directory containing the text files (character string). Will be
passed to argument |
ext |
A character string representing a file extension used to identify the files to be read. This is typically a string of three characters like, e.g., 'csv' or 'tsv'. A preceding dot is implicitly assumed to be present and must be omitted. |
sep |
The field delimiter (character) for use with
|
... |
Further optional arguments passed to |
A list, each element of which is a data frame. Element names are constructed from the source file names by stripping the specified extension and the preceeding dot.
The text files are read with read.table
using the
fixed arguments header=TRUE
and stringsAsFactors=FALSE
. Thus,
one should not try to overwrite these settings using the ...
argument. It is possible to set other optional arguments of read.table
like skip
or encoding
.
David Kneis david.kneis@tu-dresden.de
After reading the set of files, one typically wants to check the
data base for integrity using the functions check.notnull
,
check.unique
, check.key
, and
check.link
. It is probably good style to wrap all necessary
checks into a single dedicated function that can be called repeatedly
(e.g. after manipulation of data) or which can be re-used for other
data bases of the same layout. See example below.
# Read example DB shipped with the package db <- db.read(dir=system.file("examples", package="tabular"), ext="tsv") print(names(db)) # Integrity checks wrapped into a dedicated function validate <- function(db) { with(db, { stopifnot(check.key(samples, c("date","id_location"))) stopifnot(check.link(samples, "id_location", locations, "id")) # further checks would go here ... }) } validate(db)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.