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

Format

R6::R6Class object inheriting from DataBackend.

Construction

DataBackendDataTable$new(data, primary_key = NULL)

Alternatively, use as_data_backend on a data.table::data.table() which will construct a DataBackend with a copy of the data, and automatically creates a primary key column if required.

Fields

  • nrow :: integer(1)
    Number of rows (observations).

  • ncol :: integer(1)
    Number of columns (variables), including the primary key column.

  • colnames :: character()
    Returns vector of all column names, including the primary key column.

  • rownames :: integer() | character()
    Returns vector of all distinct row identifiers, i.e. the primary key column.

  • hash :: character(1)
    Returns a unique hash for this backend. This hash is cached.

  • data_formats :: character()
    Vector of supported data formats. A specific format of these supported formats can be picked in the $data() method.

Methods

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) #> #> Public: colnames, compact_seq, data_formats, data(), distinct(), hash, #> head(), missings(), ncol, nrow, primary_key, rownames #> 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$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"