DFI: Create a data.frame (or matrix) with indexes

View source: R/DFI.R

DFIR Documentation

Create a data.frame (or matrix) with indexes

Description

Turn a data.frame (or matrix) object into a DFI object allowing faster lookups on indexed columns (indexed column to be intended as DB indexes).

Usage

DFI(DF, indexes.col.names=colnames(DF))
as.DFI(DF, indexes.col.names=colnames(DF)) # exactly the same as DFI()
is.DFI(x)
## S3 method for class 'DFI'
print(x, ...)

Arguments

DF

A data.frame or matrix object (must have column names defined).

indexes.col.names

The column names for which we want to create the indexes. Only integer,numeric,logical and character are supported, so be careful since data.frame by default turns strings into factors (see data.frame stringsAsFactors argument)

x

A DFI object.

...

optional arguments passed to inner print methods of data.frame and matrix .

Details

Basically, DFI() function creates a wrapper of DF. This wrapper contains the original data.frame or matrix plus the necessary indexes data and the class of the wrapped object. These extra data will be used to perform faster lookups (in DFI.subset function) and can be extracted using the appropriate functions DFI.unWrap, DFI.indexes, DFI.getIndex.

Value

An object with class "DFI"

Note

Since version 0.0.47 DFI objects do not inherit from data.frame or matrix anymore, hence they cannot be modified/subsetted using data.frame/matrix standard operators. This has been changed since the column indexes are not recreated automatically and once the object is modified, DFI.subset could give wrong results without any warning. To use the standard replacement and subset operators, extract the original object first using DFI.unWrap(DFIobj).

See Also

DFI.subset DFI.unWrap DFI.indexes DFI.getIndex

Examples


DF <- data.frame(Foo=c(3,5,7,1,5,8,7,10),
                 Bar=c("A","B","B","C","B","B","C","A"),
                 Baz=c(TRUE,FALSE),
                 stringsAsFactors=FALSE)
DFIobj <- DFI(DF, c("Foo","Bar")) # create a DFI from DF with indexes on "Foo" and "Bar" columns


digEmAll/bsearchtools documentation built on Feb. 24, 2023, 3:52 a.m.