Since tidytensors are arrays, they support dimnames(). The usuall syntax dimnames(x) <- works; this function provides a Magritte-compatible regular function, set_dimnames(x, newnames) which returns a new tidytensor.

set_dimnames(x, newnames, ...)

Arguments

x

input tidytensor to set dimnames on.

newnames

list of dimnames to assign.

...

additional arguments to be passed to or from methods (ignored).

Value

a tidytensor with dimnames set.

Details

Setting dimnames with set_dimnames() preserves any ranknames present.

See also

ranknames<-, dimnames

Examples

t <- as.tidytensor(array(1:(3 * 2), dim = c(3, 2)))
t <- set_dimnames(t, list(c("sample1", "sample2", "sample3"), c("valset1", "valset2")))
print(t)
#> # Rank 2 tensor, shape: (3, 2)
#> |  # Rank 1 tensor, shape: (2)
#> |      1  4 
#> |  # ...

# We can also assign ranknames:
ranknames(t) <- c("sample", "valset")
print(t)
#> # Rank 2 tensor, shape: (3, 2), ranknames: sample, valset
#> |  # Rank 1 tensor, shape: (2)
#> |      1  4 
#> |  # ...