This family of functions allows you to get and set dimension names in various ways.

  • rray_dim_names() returns a list of the dimension names.

  • rray_axis_names() returns a character vector or NULL containing the names corresponding to the axis dimension.

  • rray_row_names() and rray_col_names() are helpers for getting the row and column names respectively.

  • Each of these four functions also has "set" variants: a functional form (i.e. rray_set_row_names()), and an assignment form (i.e. rray_row_names<-()).

rray_dim_names(x)

rray_dim_names(x) <- value

rray_set_dim_names(x, dim_names)

rray_axis_names(x, axis)

rray_axis_names(x, axis) <- value

rray_set_axis_names(x, axis, names, meta = NULL)

rray_row_names(x)

rray_row_names(x) <- value

rray_set_row_names(x, names, meta = NULL)

rray_col_names(x)

rray_col_names(x) <- value

rray_set_col_names(x, names, meta = NULL)

Arguments

x

The object to extract the dimension names for.

value

For rray_dim_names<-(), a list containing either character vectors or NULL corresponding to the new dimension names to use for x. Otherwise, identical to names.

dim_names

A list of either character vectors or NULL representing the new dim names of x. If NULL is supplied, the dim names of x are removed.

axis

A single integer. The axis to select dimension names for.

names

A character vector of new dimension names for the axis dimension. This is also allowed to be NULL to remove dimension names for the specified axis.

meta

A single character representing an optional "meta" name assigned to the axis names. If NULL, the current meta name is kept.

Value

rray_dim_names() returns a list of dimension names. The other names functions return character vectors, or NULL, corresponding to the names of a particular axis.

Details

Unlike dimnames() which can return NULL, rray_dim_names() always returns a list the same length as the dimensionality of x. If any dimensions do not have names, NULL is returned for that element of the list. This results in an object that's length always matches the dimensionality of x.

Examples

x <- rray(1:10, c(5, 2)) rray_dim_names(x) <- list(letters[1:5], NULL) x
#> <rray<int>[,2][5]> #> [,1] [,2] #> a 1 6 #> b 2 7 #> c 3 8 #> d 4 9 #> e 5 10
rray_dim_names(x)
#> [[1]] #> [1] "a" "b" "c" "d" "e" #> #> [[2]] #> NULL #>
# 3D object, so 3 dim name elements rray_dim_names(rray(1, dim = c(1, 1, 1)))
#> [[1]] #> NULL #> #> [[2]] #> NULL #> #> [[3]] #> NULL #>
# Vectors are treated as 1D arrays vec <- c(x = 1, y = 2) rray_dim_names(vec)
#> [[1]] #> [1] "x" "y" #>
# You can add dim names more easily # using rray_set_axis_names() # and the pipe operator library(magrittr) y <- rray(1, c(1, 2, 1)) %>% rray_set_axis_names(1, "r1") %>% rray_set_axis_names(2, c("c1", "c2")) %>% rray_set_axis_names(3, "3rd dim") y
#> <rray<dbl>[,2,1][1]> #> , , 3rd dim #> #> c1 c2 #> r1 1 1 #>
# You can set also set axis names to `NULL` to reset them rray_set_axis_names(y, 2, NULL)
#> <rray<dbl>[,2,1][1]> #> , , 3rd dim #> #> [,1] [,2] #> r1 1 1 #>
# You can set the "meta" names of an axis as well rray_set_axis_names(y, 1, "r1", "row names")
#> <rray<dbl>[,2,1][1]> #> , , = 3rd dim #> #> #> row names c1 c2 #> r1 1 1 #>