pad() is used alongside the standard rray subsetting operator [ (and the underlying rray_subset() function) to easily subset into higher dimensions without having to explicitly list the intermediate commas.

pad()

Value

An object that can be used to pad dimensions with when subsetting.

Examples

x <- rray(1:4, c(1, 1, 2, 2)) # pad() fills in the missing dimensions # essentially it adds commas automatically # second element in the 4th dimension x[pad(), 2]
#> <rray<int>[,1,2,1][1]> #> , , 1, 1 #> #> [,1] #> [1,] 3 #> #> , , 2, 1 #> #> [,1] #> [1,] 4 #>
# vs using x[,,,2]
#> <rray<int>[,1,2,1][1]> #> , , 1, 1 #> #> [,1] #> [1,] 3 #> #> , , 2, 1 #> #> [,1] #> [1,] 4 #>
# second element in 3rd # first element in 4th x[pad(), 2, 1]
#> <rray<int>[,1,1,1][1]> #> , , 1, 1 #> #> [,1] #> [1,] 2 #>
# can fill in the missing gaps too # this fills in the 2nd/3rd dimensions x[1, pad(), 1]
#> <rray<int>[,1,2,1][1]> #> , , 1, 1 #> #> [,1] #> [1,] 1 #> #> , , 2, 1 #> #> [,1] #> [1,] 2 #>
# if a pad() isn't needed # because the dimensionality is already fully # specified by the indices, its ignored x_flat <- rray_reshape(x, 4) x_flat[pad(), 1]
#> <rray<int>[1]> #> [1] 1
x_flat[1, pad()]
#> <rray<int>[1]> #> [1] 1
# `pad()` can be used with base R # objects as well through `rray_subset()` x_arr <- as.array(x) rray_subset(x_arr, pad(), 1)
#> , , 1, 1 #> #> [,1] #> [1,] 1 #> #> , , 2, 1 #> #> [,1] #> [1,] 2 #>