Obtain a list of common dimension names among a set of objects. For
interactive use, rray_dim_names_common()
is more useful.
rray_dim_names_common(...) rray_dim_names2(x, y)
x, y, ... | Objects to find common dimensions for. |
---|
A list of the common dimension names of the inputs.
rray_dim_names_common()
is the engine that determines what dim names should
be used in the result of arithmetic operations and other functions that
involve multiple rray objects and return a single result.
The rules for determining the set of common dim names between objects
x
and y
(in that order) are:
Compute the common dim
between x
and y
using rray_dim_common()
.
For each axis along the common dim
:
If x
has names for that axis and the size of the names vector
is the same as the size of the axis, use those names for that axis.
Else if y
has names for that axis and the size of the names vector
is the same as the size of the axis, use those names for that axis.
Otherwise, the names for that axis is NULL
.
library(magrittr) # 1x2 - Row names but no column names x <- rray(1, dim = c(1, 2)) %>% rray_set_row_names("r_from_x") # 1x1 - Row names and column names y <- rray(1, dim = c(1, 1)) %>% rray_set_col_names("c_from_y") %>% rray_set_row_names("r_from_y") # 1x1 - Row names but no column names z <- rray(1, c(1, 1)) %>% rray_set_row_names("r_from_z") # Combining y and z # y has names for both dimensions # so they are used rray_dim_names_common(y, z)#> [[1]] #> [1] "r_from_y" #> #> [[2]] #> [1] "c_from_y" #># Combining z and y # - Row names are found first from z # - But z has no column names # - So column names are found from y rray_dim_names_common(z, y)#> [[1]] #> [1] "r_from_z" #> #> [[2]] #> [1] "c_from_y" #># Combining x and y # - Row names are found first from x # - x has no column names # - y has column names but they are # a different length from the common # column dimension (common size of 2) # - So no column names are used rray_dim_names_common(x, y)#> [[1]] #> [1] "r_from_x" #> #> [[2]] #> NULL #>