readFKtable: Read table with Foreign Keys

View source: R/readFKtable.R

readFKtableR Documentation

Read table with Foreign Keys

Description

The concept Foreign Keys comes from relational databse systems. These keys can be used to cross-reference tables. Say we have two data.frames, one contains gene annotations and the other contains protein annotations. A column named mRNArefseqID may be the foreign key that can be used to specify relationships between gene and proteins.

Usage

readFKtable(file, fk, strict.order = FALSE, ...)

Arguments

file

A table file.

fk

Characters, foreign keys.

strict.order

Logical, whether the foreign keys must have the same order as they appear in the file.

...

Other parameters passed to the read.table function.

Details

The readFKtable reads a table from file, and checks if it contains provided foreign keys: either as row.names or in the first column.

Value

A data.frame if the FK-matching was successful, otherwise the function will print an error message and stop.

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

Examples


test.file <- tempfile()
fk.teams <- c("HSV", "FCB", "BVB")
## FK in row names
test.mat <- matrix(rnorm(9), nrow=3, dimnames=list(fk.teams, NULL))
write.table(test.mat, test.file)
readFKtable(test.file, fk=fk.teams)

## or: FK can be in the first column
test.df <- data.frame(team=fk.teams, pts=c(15,14,15),plc=c("H", "G", "H"))
write.table(test.df, test.file)
readFKtable(test.file, fk=fk.teams)

## try strict.order=TRUE
test.df <- data.frame(pts=c(15,14,13), plc=c("H", "G", "H"), row.names=rev(fk.teams))
write.table(test.df, test.file)
readFKtable(test.file, fk=fk.teams, strict.order=FALSE)
## Not run: readFKtable(test.file, fk=fk.teams, strict.order=TRUE)


bedapub/ribiosExpression documentation built on Sept. 2, 2023, 4:37 a.m.