Skip to content

Commit

Permalink
Fix namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Sep 18, 2023
1 parent 1a8e187 commit 79ff801
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 38 deletions.
34 changes: 33 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
exportPattern("^[[:alpha:]]+")
# Generated by roxygen2: do not edit by hand

export(Attributes)
export(BloscCodec)
export(Bz2Codec)
export(Codec)
export(DirectoryStore)
export(Dtype)
export(GzipCodec)
export(HttpStore)
export(Lz4Codec)
export(LzmaCodec)
export(MemoryStore)
export(NestedArray)
export(Store)
export(VLenUtf8Codec)
export(ZarrArray)
export(ZarrGroup)
export(ZlibCodec)
export(ZstdCodec)
export(as_scalar)
export(is_key_error)
export(is_scalar)
export(is_slice)
export(obj_list)
export(slice)
export(zarr_create)
export(zarr_create_array)
export(zarr_create_empty)
export(zarr_create_group)
export(zarr_create_zeros)
export(zarr_open_group)
export(zb_slice)
2 changes: 2 additions & 0 deletions R/atomic.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#' Convert a value to a scalar to opt-out of R default vector casting behavior.
#' @param obj The value to convert.
#' @return The value wrapped as a scalar.
#' @export
as_scalar <- function(obj) {
return(jsonlite::unbox(obj))
}

#' Check if a value is a scalar.
#' @param s The value to check.
#' @return TRUE if the value is a scalar, FALSE otherwise.
#' @export
is_scalar <- function(s) {
if(class(s)[[1]] == "scalar") {
return(TRUE)
Expand Down
6 changes: 6 additions & 0 deletions R/creation.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ init_group <- function(
#' non-fill-value data are stored, at the expense of overhead associated
#' with checking the data of each chunk.
#' @returns ZarrArray
#' @export
zarr_create <- function(
shape,
chunks=TRUE,
Expand Down Expand Up @@ -451,6 +452,7 @@ zarr_create <- function(
#' @param shape : int or tuple of ints
#' @param ... The params of zarr_create()
#' @returns ZarrArray
#' @export
zarr_create_empty <- function(shape, ...) {
return(zarr_create(shape=shape, fill_value=NA, ...))
}
Expand All @@ -459,6 +461,7 @@ zarr_create_empty <- function(shape, ...) {
#' @param data A base R array() or pizzarr NestedArray instance.
#' @param ... The params of zarr_create()
#' @returns ZarrArray
#' @export
zarr_create_array <- function(data, ...) {
z <- zarr_create(...)
z$set_item("...", data)
Expand All @@ -470,6 +473,7 @@ zarr_create_array <- function(data, ...) {
#' @param shape : int or tuple of ints
#' @param ... The params of zarr_create()
#' @returns ZarrArray
#' @export
zarr_create_zeros <- function(shape, ...) {
return(zarr_create(shape=shape, fill_value=0, ...))
}
Expand All @@ -492,6 +496,7 @@ zarr_create_zeros <- function(shape, ...) {
#' @param path : string, optional
#' Group path within store.
#' @returns ZarrGroup
#' @export
zarr_create_group <- function(
store = NA,
overwrite = FALSE,
Expand Down Expand Up @@ -545,6 +550,7 @@ zarr_create_group <- function(
#' If using an fsspec URL to create the store, these will be passed to
#' the backend implementation. Ignored otherwise.
#' @returns ZarrGroup
#' @export
zarr_open_group <- function(
store = NA,
mode = NA,
Expand Down
2 changes: 1 addition & 1 deletion R/dtypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ get_dtype_asrtype <- function(dtype) {
#' @description
#'
#' @rdname Dtype
#' @keywords internal
#' @export
Dtype <- R6::R6Class("Dtype",
public = list(
#' @field dtype The original dtype string, like "<f4".
Expand Down
29 changes: 14 additions & 15 deletions R/indexing.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L655

#' The Zarr OIndex class.
#' @title OIndex Class
#' @docType class
#' @description
#' @keywords internal
#' Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L655
#'
#' @rdname OIndex
#' @export
#' @keywords internal
OIndex <- R6::R6Class("OIndex",
public = list(
#' @field array
Expand All @@ -21,15 +21,15 @@ OIndex <- R6::R6Class("OIndex",
)
)

# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L811

#' The Zarr VIndex class.
#' @title VIndex Class
#' @docType class
#' @description
#' @keywords internal
#' Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L811
#'
#' @rdname VIndex
#' @export
#' @keywords internal
VIndex <- R6::R6Class("VIndex",
public = list(
#' @field array
Expand All @@ -44,16 +44,15 @@ VIndex <- R6::R6Class("VIndex",
)
)

# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L138

#' The Zarr IntDimIndexer class.
#' @title IntDimIndexer Class
#' @docType class
#' @description
#' @keywords internal
#' Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L138
#'
#' @rdname IntDimIndexer
#' @export
#' @keywords internal
IntDimIndexer <- R6::R6Class("IntDimIndexer",
inherit = DimIndexer,
public = list(
Expand Down Expand Up @@ -95,15 +94,15 @@ IntDimIndexer <- R6::R6Class("IntDimIndexer",
)
)

# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L163

#' The Zarr SliceDimIndexer class.
#' @title SliceDimIndexer Class
#' @docType class
#' @description
#' @keywords internal
#' Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L163
#'
#' @rdname SliceDimIndexer
#' @export
#' @keywords internal
SliceDimIndexer <- R6::R6Class("SliceDimIndexer",
inherit = DimIndexer,
public = list(
Expand Down Expand Up @@ -196,15 +195,15 @@ SliceDimIndexer <- R6::R6Class("SliceDimIndexer",
)
)

# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L326

#' The Zarr BasicIndexer class.
#' @title BasicIndexer Class
#' @docType class
#' @description
#' @keywords internal
#' Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0/zarr/indexing.py#L326
#'
#' @rdname BasicIndexer
#' @export
#' @keywords internal
BasicIndexer <- R6::R6Class("BasicIndexer",
inherit = Indexer,
public = list(
Expand Down
1 change: 1 addition & 0 deletions R/meta.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0e6cdc04c6413e14f57f61d389972ea937c/zarr/meta.py#L14
#' @keywords internal
Metadata2 <- R6::R6Class("Metadata2",
private = list(
ZARR_FORMAT = 2
Expand Down
4 changes: 3 additions & 1 deletion R/slicing.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Slice <- R6::R6Class("Slice",
#' @param step The step size.
#' @param zero_based The index of the dimension. By default, FALSE for R-like behavior.
#' @return A Slice instance with the specified parameters.
#' @export
slice <- function(start, stop = NA, step = NA, zero_based = FALSE) {
start_offset <- ifelse(zero_based, 0, -1)
stop_offset <- ifelse(zero_based, 0, 0)
Expand All @@ -108,14 +109,15 @@ slice <- function(start, stop = NA, step = NA, zero_based = FALSE) {
#' @param start The start index.
#' @param stop The stop index.
#' @param step The step size.
#' @keywords internal
#' @export
zb_slice <- function(start, stop = NA, step = NA) {
return(slice(start, stop, step, zero_based = TRUE))
}

#' Check if a value is a Slice instance.
#' @param s The value to check.
#' @return TRUE if the value is a Slice instance, FALSE otherwise.
#' @export
is_slice <- function(s) {
if(class(s)[[1]] == "Slice") {
return(TRUE)
Expand Down
3 changes: 2 additions & 1 deletion R/string-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ char_vec_to_raw <- function(char_vec, basic_type, num_chars, byte_order) {
return(buf)
}

#' @keywords internal
raw_to_char_vec <- function(raw_vec, basic_type, num_chars, byte_order) {
# Reference: https://stat.ethz.ch/R-manual/R-devel/library/base/html/iconv.html
if(basic_type == "S") {
Expand Down Expand Up @@ -101,4 +102,4 @@ raw_to_char_vec <- function(raw_vec, basic_type, num_chars, byte_order) {
}
char_vec <- iconv(list_of_raw, from = iconv_from, to = "UTF-8", toRaw = FALSE)
return(char_vec)
}
}
17 changes: 10 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#' Convert a string into a character vector.
#'
#' @keywords internal
#' @param s The string.
#' @return A vector where each element is an individual character.
#' @keywords internal
str_to_vec <- function(s) {
return(stringr::str_split(s, pattern = "")[[1]])
}

#' Create a list of zarray metadata.
#'
#' @keywords internal
#' @param shape
#' @param chunks
#' @param dtype
Expand All @@ -19,6 +18,7 @@ str_to_vec <- function(s) {
#' @param filters
#' @param dimension_separator
#' @return A list.
#' @keywords internal
create_zarray_meta <- function(shape = NA, chunks = NA, dtype = NA, compressor = NA, fill_value = NA, order = NA, filters = NA, dimension_separator = NA) {
# Reference: https://zarr.readthedocs.io/en/stable/spec/v2.html#metadata
if(is.na(dimension_separator)) {
Expand Down Expand Up @@ -101,7 +101,7 @@ obj_list <- function(...) {
retval
}


#' @keywords internal
zip_numeric <- function(a, b) {
result <- list()
for(i in seq_len(length(a))) {
Expand All @@ -110,6 +110,7 @@ zip_numeric <- function(a, b) {
return(result)
}

#' @keywords internal
check_selection_length <- function(selection, shape) {
if(length(selection) > length(shape)) {
stop('TooManyIndicesError')
Expand All @@ -118,6 +119,7 @@ check_selection_length <- function(selection, shape) {

# Returns both the sliceIndices per dimension and the output shape after slicing.
# Reference: https://github.com/gzuidhof/zarr.js/blob/master/src/core/indexing.ts#L22
#' @keywords internal
selection_to_slice_indices <- function(selection, shape) {
slice_indices_result <- list()
out_shape <- c()
Expand Down Expand Up @@ -152,10 +154,10 @@ filter_list <- function(l, pred) {

#' Convert user selections, potentially containing "...", to a list of slices
#' that can be used internally.
#' @keywords internal
#' @param selection The user-provided selection list.
#' @param shape The shape of the array, to be used to fill in ellipsis values.
#' @returns A list of selections with ellipsis values converted to NA.
#' @keywords internal
replace_ellipsis <- function(selection, shape) {
# Reference: https://github.com/gzuidhof/zarr.js/blob/master/src/core/indexing.ts#L67

Expand Down Expand Up @@ -215,9 +217,9 @@ replace_ellipsis <- function(selection, shape) {
return(selection)
}

#' @keywords internal
#' @param shape A shape vector
#' @returns The product of shape elements.
#' @keywords internal
compute_size <- function(shape) {
result <- 1
for(val in shape) {
Expand All @@ -228,9 +230,9 @@ compute_size <- function(shape) {

#' Check if a value, potentially a vector, is NA
#'
#' @keywords internal
#' @param val The value to check
#' @return Whether the value is NA
#' @keywords internal
is_na <- function(val) {
if(length(val) != 1) {
# Including when val is integer(0), character(0), etc.
Expand All @@ -255,6 +257,7 @@ chunk_fill <- function(chunk, value) {
#' Check if an error is a KeyError.
#' @param e The error to check.
#' @return TRUE if the error is a KeyError, FALSE otherwise.
#' @export
is_key_error <- function(e) {
return(grepl("KeyError", e$message))
}
Expand All @@ -277,8 +280,8 @@ get_list_product_aux <- function(dim_indexer_iterables, i, partial_results) {

#' Generate a product of lists.
#' @param dim_indexer_iterables A list of lists.
#' @keywords internal
#' @return A list of lists.
#' @keywords internal
get_list_product <- function(dim_indexer_iterables) {
# Reference: https://docs.python.org/3/library/itertools.html#itertools.product
partial_results <- list()
Expand Down
2 changes: 0 additions & 2 deletions man/BasicIndexer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/Dtype.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/IntDimIndexer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/OIndex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/SliceDimIndexer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 79ff801

Please sign in to comment.