data.frame standard R class, following the object-oriented paradigm. The use of Reference Class system allows significative memory and time saving, making this class more suitable than data.frame to handle large tabular data. Objects can be created by two distincts means :
refTable constructor, similar to the data.frame constructor. It imports a single data.frame or a collection of vectors into the object, and check immediatly for validity.
new function (standard behavior for S4 and reference classes), which produces an empty object and do NOT check for validity. You can provide as arguments the values to use as the new object fields, if you know what you are doing.
values field as vectors. As values is an environment, manipulating a refTable implies a pass-by-reference paradigm rather than the standard R pass-by-copy, i.e. data duplication (and so time and memory wasting) is widely reduced. As an example, updating a single cell in a data.frame leads to the duplication of the whole table in memory ('before' and 'after' versions), while in a refTable the duplication is limited to the involved column. values are not named according to the user-level column names, but according to references stored in the colReferences field (integers greater than 0 converted to characters). Rename a column only updates the colNames field and leave the values one alone, as the column reference does not change. data.frame, for a more comfortable R usage. The extraction mechanism handles data.frame extraction mechanisms, and relies on the indexes method to handle the others. data.frame and vectors.
TRUE) or not (FALSE). Such vectors are recycled if not long enough to cover all the rows / columns.
NULL value may be used to select all rows / columns.
expression or parse may be used to select rows in the table environment. See 'examples'.
colCount:integer value, the amount of rows in the table.colIterator:integer value, last column reference used.colNames:Character vector, the names of all rows (may be empty).colReferences:Character vector, the column names in the values environment.rowCount:integer value, the amount of rows in the table.rowNamed:logical value, whether row names should be considered or not.rowNames:Character vector, the names of all rows (may be empty).values:environment storing the columns as vectors.addColumn(content, name, after = ):addDataFrame(dataFrame):addEmptyRows(amount, newNames):addList(dataList, row.names):addVectors(..., row.names):check(warn = ):coerce(j = , class, levels, ...):colOrder(newOrder, na.last = , decreasing = ):delColumns(targets):erase():extract(i = , j = , drop = , asObject = ):fill(i = , j = , newValues):getColCount():getColNames():getLevels(j = ):getRowCount():getRowNames():indexes(i, type = ):initialize(rowCount = , rowNames = , rowNamed = , colCount = , colNames = , colReferences = , colIterator = , values = , ...):metaFields():rowOrder(newOrder, na.last = , decreasing = ):setColNames(j, value):setLevels(j = , newLevels):setRowNames(value):types(j = ): # New empty refTable
tab <- new("refTable")
tab$addColumn(1:5, "C1")
tab$addColumn(letters[1:5], "C2")
tab$setRowNames(LETTERS[11:15])
# New filled refTable (same content)
tab <- refTable(C1=1:5, C2=letters[1:5], row.names=LETTERS[11:15])
# Whole table print
print(tab$extract())
# Data update
tab$fill(c(2,4), 2, c("B","D"))
# Data extraction
print(tab$extract(1:3))
print(tab$extract(c(TRUE, FALSE)))
print(tab$extract("K", "C1"))
# Expression-based extraction
expr <- expression(C1 %% 2 == 1)
print(tab$extract(expr))
# Table extension
tab$addEmptyRows(5L, LETTERS[1:5])
tab$fill(6:10, "C1", 6:10)
print(tab$extract())
# Filling from R objects
tab <- new("refTable")
print(tab$extract())
tab$addVectors(C1=1:5, C2=letters[1:5])
print(tab$extract())
tab$addList(list(C1=6:8, C3=LETTERS[6:8]))
print(tab$extract())
# Beware of recycling !
tab$addVectors(C1=9:15, C3=LETTERS[9:10])
print(tab$extract())
Run the code above in your browser using DataLab