DataBackend for data.table as an in-memory data base.

Format

R6::R6Class object inheriting from DataBackend.

Construction

DataBackendDataTable$new(data, primary_key = NULL)
as_data_backend(data, primary_key = NULL, ...)

DataBackendDataTable does not copy the input data, while as_data_backend calls data.table::copy(). as_data_backend creates a primary key column as integer column if primary_key is NULL.

Fields

See DataBackend.

Methods

See DataBackend.

See also

Examples

data = as.data.table(iris) data$id = seq_len(nrow(iris)) b = DataBackendDataTable$new(data = data, primary_key = "id") print(b)
#> <DataBackendDataTable> (150x6) #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species id #> 5.1 3.5 1.4 0.2 setosa 1 #> 4.9 3.0 1.4 0.2 setosa 2 #> 4.7 3.2 1.3 0.2 setosa 3 #> 4.6 3.1 1.5 0.2 setosa 4 #> 5.0 3.6 1.4 0.2 setosa 5 #> 5.4 3.9 1.7 0.4 setosa 6 #> [...] (144 rows omitted)
b$head()
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species id #> 1: 5.1 3.5 1.4 0.2 setosa 1 #> 2: 4.9 3.0 1.4 0.2 setosa 2 #> 3: 4.7 3.2 1.3 0.2 setosa 3 #> 4: 4.6 3.1 1.5 0.2 setosa 4 #> 5: 5.0 3.6 1.4 0.2 setosa 5 #> 6: 5.4 3.9 1.7 0.4 setosa 6
b$data(rows = 100:101, cols = "Species")
#> Species #> 1: versicolor #> 2: virginica
b$nrow
#> [1] 150
head(b$rownames)
#> [1] 1 2 3 4 5 6
b$ncol
#> [1] 6
b$colnames
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" #> [6] "id"
# alternative construction as_data_backend(iris)
#> <DataBackendDataTable> (150x6) #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species ..row_id #> 5.1 3.5 1.4 0.2 setosa 1 #> 4.9 3.0 1.4 0.2 setosa 2 #> 4.7 3.2 1.3 0.2 setosa 3 #> 4.6 3.1 1.5 0.2 setosa 4 #> 5.0 3.6 1.4 0.2 setosa 5 #> 5.4 3.9 1.7 0.4 setosa 6 #> [...] (144 rows omitted)