Skip to contents

Wraps a DataBackend around data. mlr3 ships with methods for data.frame (converted to a DataBackendDataTable and Matrix from package Matrix (converted to a DataBackendMatrix).

Additional methods are implemented in the package mlr3db, e.g. to connect to real DBMS like PostgreSQL (via dbplyr) or DuckDB (via DBI/duckdb).

Usage

# S3 method for class 'Matrix'
as_data_backend(data, primary_key = NULL, dense = NULL, ...)

as_data_backend(data, primary_key = NULL, ...)

# S3 method for class 'data.frame'
as_data_backend(data, primary_key = NULL, keep_rownames = FALSE, ...)

Arguments

data

(data.frame())
The input data.frame(). Automatically converted to a data.table::data.table().

primary_key

(character(1) | integer())
Name of the primary key column, or integer vector of row ids.

dense

(data.frame()). Dense data.

...

(any)
Additional arguments passed to the respective DataBackend method.

keep_rownames

(logical(1) | character(1))
If TRUE or a single string, keeps the row names of data as a new column. The column is named like the provided string, defaulting to "..rownames" for keep_rownames == TRUE. Note that the created column will be used as a regular feature by the task unless you manually change the column role. Also see data.table::as.data.table().

Value

DataBackend.

See also

Examples

# create a new backend using the penguins data:
as_data_backend(palmerpenguins::penguins)
#> <DataBackendDataTable> (344x9)
#>  species    island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
#>   <fctr>    <fctr>          <num>         <num>             <int>       <int>
#>   Adelie Torgersen           39.1          18.7               181        3750
#>   Adelie Torgersen           39.5          17.4               186        3800
#>   Adelie Torgersen           40.3          18.0               195        3250
#>   Adelie Torgersen             NA            NA                NA          NA
#>   Adelie Torgersen           36.7          19.3               193        3450
#>   Adelie Torgersen           39.3          20.6               190        3650
#>     sex  year ..row_id
#>  <fctr> <int>    <int>
#>    male  2007        1
#>  female  2007        2
#>  female  2007        3
#>    <NA>  2007        4
#>  female  2007        5
#>    male  2007        6
#> [...] (338 rows omitted)