pad: Pad missing dimensions when subsetting

Description Usage Value Examples

View source: R/pad.R

Description

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.

Usage

1
pad()

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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]

# vs using
x[,,,2]

# second element in 3rd
# first element in 4th
x[pad(), 2, 1]

# can fill in the missing gaps too
# this fills in the 2nd/3rd dimensions
x[1, pad(), 1]

# 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]
x_flat[1, pad()]

# `pad()` can be used with base R
# objects as well through `rray_subset()`
x_arr <- as.array(x)
rray_subset(x_arr, pad(), 1)

rray documentation built on July 23, 2019, 5:04 p.m.