Description Format Construction Active Fields (read-only) Methods
The base class (first building block) for Agent, Asset and Environment.
R6::R6Class object.
1 |
Stores .data
as a DataBackend object inside the object's list of data (private$.data
)
and registers the id_col
(private$.id_col
).
databackend
:: an R6::R6Class generator]
An R6::R6Class generator that inherits from DataBackend
.
.data
:: data.frame()
A object that inherits from data.frame
.
id_col
:: character()
The name of the id column of .data
and all relation columns. The first
element will be checked as the main id column of the entity data, which
must be unique integers. The rest of the vector will be consider as relation
columns. For example, if c("pid", "partner_id")
is given pid
must contain
unique integers, while partner_id
can be NA
or non-unique integers.
database
: a list of DataBackend objects that Entity possess.
id_col
: a character vector of all id columns with the first element being
the main id column and the other elements, if any, are relation columns.
data_template
: a data.table object that contains the minimum data requirement apart
from the id_col
.
add_data(databackend = DataBackendDataTable, .data, name)
(DataBackend
, data.frame
, character(1)
) -> NULL
Append new data to the object's data list (private$.data
). the new data
must be linkable with the attribute data of the object by the id_col.
data(name)
(character(1)
) -> ([dymiumCore::DataBackend]
|NULL
)
Returns a DataBackend with the name that matches name
.
If name
is not given, the function will try to return the DataBackend with name attrs
.
If attrs
is not present or no DataBackEnd
objects have been loaded it will
return NULL
.
add(.data, check_existing = FALSE)
(data.table::data.table()
, logical(1)
)
Add attribute data of new entities. This makes sure none of the ids
of the new entities are the same as the existing entity records. However, other id columns,
relation columns can be exempted from the check by setting check_existing
as FALSE
.
Meaning, the other id columns can contain ids of the existing entities.
get_id_col
() -> character(1)
Returns the column id field of data.
get_data(ids, copy = TRUE)
(integer()
, logical(1)
) -> ([data.table::data.table()]
|NULL
)
Return agent data. When ids
is specified, the data returned has the same
row order as the order of ids
. If copy
is TRUE then data.table's
reference semantics is returned. If attrs
is not present or no DataBackEnd
objects have been loaded it will return NULL
.
get_data_names()
() -> character()
Returns the names of all data objects (in private$.data
) that belongs to this object.
get_removed_data(name)
(character(1)
) -> data.table::data.table()
Return removed agent data. If name
is missing, the first data, which should
contains the main attributes of the agent object, will be returned.
get_ids(include_removed =
FALSE)
(logical(1)
) -> integer()
Return the ids of the indexes in the argrument idx
, respectively. If include_removed
is TRUE
, ids of removed data will also be returned.
get_idx(ids)
(integer()
) -> integer()
Return the indexes of the ids in the argrument ids
, respectively.
get_attr(x, ids)
(character(1)
, integer()
) -> vector(type::col)
Extract the attribute from self$data as vector. If ids
is given then only
the corresponding values to ids
are returned, in the same order as the ids
.
has_attr(x)
(character()
) -> logical()
Check which of the attribute names given in x
exist in the attribute data
of the object.
ids_exist(ids, include_removed_data = FALSE)
(integer()
, logical(1)
) -> logical()
Check whether ids
exist or not. And if inclide_removed_data
is TRUE
it
will also check the removed data.
idx_exist(idx, by_element = FALSE)
(integer()
) -> logical()
Returns a logical vector of the same length as the argument idx
. This function
checks whether the indexes in the argument idx
exist or not. If by_element
is
TRUE then it will return a logical vector with the same length as ids
in
their respective order.
n()
() -> integer(1)
Returns the number of entities represented by this object.
print_data(n = 0)
(logical(1)
) -> self
Print to console the number of datasets and their dimensions. n
is the number of rows
that will be output to console by head()
, if 0 nothing will be printed.
subset_ids(expr)
(expr
) -> [data.table::data.table()]
Return ids of rows matches the expression.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.