Skip to contents

User-friendly constructor that concatenates scalars, vectors, matrices, and tensors into the flat data slot of Contract(), and converts axes (a list of axis_contract() records) into the named-list form the underlying class expects.

Usage

create_contract(
  scalars = list(),
  vectors = list(),
  matrices = list(),
  tensors = list(),
  axes = list(),
  is_relaxed = FALSE
)

Arguments

scalars

List of contract_scalar() records.

vectors

List of contract_vector() records.

matrices

List of contract_matrix() records.

tensors

List of tensor_contract() records.

axes

List of axis_contract() records.

is_relaxed

Logical; if TRUE, accesses to properties outside the contract are allowed at enforcement time.

Value

A Contract() object.

Examples

create_contract(
    axes = list(
        axis_contract("cell", RequiredInput, "per-cell axis"),
        axis_contract("gene", RequiredInput, "per-gene axis")
    ),
    scalars = list(contract_scalar("organism", RequiredInput, "character", "species")),
    vectors = list(contract_vector("cell", "donor", RequiredInput, "character", "donor id")),
    matrices = list(contract_matrix("cell", "gene", "UMIs", RequiredInput, "integer", "UMIs"))
)
#> <dafr::Contract>
#>  @ name      : chr ""
#>  @ is_relaxed: logi FALSE
#>  @ axes      :List of 2
#>  .. $ cell:List of 2
#>  ..  ..$ : chr "RequiredInput"
#>  ..  ..$ : chr "per-cell axis"
#>  .. $ gene:List of 2
#>  ..  ..$ : chr "RequiredInput"
#>  ..  ..$ : chr "per-gene axis"
#>  @ data      :List of 3
#>  .. $ :List of 5
#>  ..  ..$ kind       : chr "scalar"
#>  ..  ..$ name       : chr "organism"
#>  ..  ..$ expectation: chr "RequiredInput"
#>  ..  ..$ type       : chr "character"
#>  ..  ..$ description: chr "species"
#>  .. $ :List of 6
#>  ..  ..$ kind       : chr "vector"
#>  ..  ..$ axis       : chr "cell"
#>  ..  ..$ name       : chr "donor"
#>  ..  ..$ expectation: chr "RequiredInput"
#>  ..  ..$ type       : chr "character"
#>  ..  ..$ description: chr "donor id"
#>  .. $ :List of 7
#>  ..  ..$ kind        : chr "matrix"
#>  ..  ..$ rows_axis   : chr "cell"
#>  ..  ..$ columns_axis: chr "gene"
#>  ..  ..$ name        : chr "UMIs"
#>  ..  ..$ expectation : chr "RequiredInput"
#>  ..  ..$ type        : chr "integer"
#>  ..  ..$ description : chr "UMIs"