Skip to contents

Convenience function for the internal Slice R6 class constructor.

Usage

slice(start, stop = NA, step = NA, zero_based = FALSE)

Arguments

start

The start index.

stop

The stop index.

step

The step size. Negative values reverse the direction of the slice, matching Python/NumPy semantics (e.g., step = -1 iterates backward from start toward stop).

zero_based

The index of the dimension. By default, FALSE for R-like behavior.

Value

A Slice instance with the specified parameters.

Examples

g <- zarr_volcano()
v <- g$get_item("volcano")

# Reverse the first 5 columns of row 1 (zero-based: 5:0:-1)
v$get_orthogonal_selection(list(zb_slice(0, 1), zb_slice(5, 0, -1)))
#> <NestedArray>
#>   Public:
#>     as.array: function () 
#>     clone: function (deep = FALSE) 
#>     data: 101 101 101 101 100
#>     dtype: NULL
#>     dtype_obj: Dtype, R6
#>     flatten: function (order = NA) 
#>     flatten_to_raw: function (order = NA) 
#>     get: function (selection) 
#>     initialize: function (data, shape = NA, dtype = NA, order = NA) 
#>     set: function (selection, value) 
#>     shape: 1 5
#>   Private:
#>     dtype_basic_type: NULL
#>     dtype_byte_order: NULL
#>     dtype_num_bytes: NULL
#>     dtype_num_items: NULL
#>     is_zero_dim: FALSE

# Full reverse of row 1 (zero-based: -1::-1)
v$get_orthogonal_selection(list(zb_slice(0, 1), zb_slice(-1, NA, -1)))
#> <NestedArray>
#>   Public:
#>     as.array: function () 
#>     clone: function (deep = FALSE) 
#>     data: 103 104 104 105 105 106 106 107 107 107 107 108 108 108  ...
#>     dtype: NULL
#>     dtype_obj: Dtype, R6
#>     flatten: function (order = NA) 
#>     flatten_to_raw: function (order = NA) 
#>     get: function (selection) 
#>     initialize: function (data, shape = NA, dtype = NA, order = NA) 
#>     set: function (selection, value) 
#>     shape: 1 61
#>   Private:
#>     dtype_basic_type: NULL
#>     dtype_byte_order: NULL
#>     dtype_num_bytes: NULL
#>     dtype_num_items: NULL
#>     is_zero_dim: FALSE