}}
\describe{
-\item{\code{selection}}{Selections are lists containing either scalars, strings, or Slice objects.}
+\item{\code{selection}}{Selections are lists containing either scalars, strings, or Slice objects. Two character
+literals are supported: "..." selects all remaining array dimensions and ":" selects all of a specific
+array dimension.}
\item{\code{value}}{TODO}
@@ -869,7 +887,9 @@ TODO
\subsection{Arguments}{
\if{html}{\out{
}}
\describe{
-\item{\code{selection}}{Selections are lists containing either scalars, strings, or Slice objects.}
+\item{\code{selection}}{Selections are lists containing either scalars, strings, or Slice objects. Two character
+literals are supported: "..." selects all remaining array dimensions and ":" selects all of a specific
+array dimension.}
\item{\code{value}}{TODO}
@@ -1018,7 +1038,7 @@ Set values for a selection using bracket notation (for S3 method).
\if{html}{\out{
}}
\describe{
\item{\code{...}}{Contains the slicing parameters, one for each dimension.
-Use empty space to get whole dimension e.g. \link{1:5,,}}
+Use empty space to get whole dimension e.g. \code{[1:5,,]}}
}
\if{html}{\out{
}}
}
@@ -1039,7 +1059,7 @@ Assign values for a selection using bracket notation (for S3 method).
\if{html}{\out{
}}
\describe{
\item{\code{...}}{Contains the slicing parameters, one for each dimension.
-Use empty space to get whole dimension e.g. \link{1:5,,}}
+Use empty space to get whole dimension e.g. \code{[1:5,,]}}
}
\if{html}{\out{
}}
}
diff --git a/man/as.array.NestedArray.Rd b/man/as.array.NestedArray.Rd
index 02b44f3..0c6ee64 100644
--- a/man/as.array.NestedArray.Rd
+++ b/man/as.array.NestedArray.Rd
@@ -4,10 +4,10 @@
\alias{as.array.NestedArray}
\title{S3 method for as.array}
\usage{
-\method{as.array}{NestedArray}(obj)
+\method{as.array}{NestedArray}(x, ...)
}
\arguments{
-\item{obj}{}
+\item{x}{}
}
\description{
S3 method for as.array
diff --git a/man/as.array.ZarrArray.Rd b/man/as.array.ZarrArray.Rd
index 6164fd1..2a8c3e6 100644
--- a/man/as.array.ZarrArray.Rd
+++ b/man/as.array.ZarrArray.Rd
@@ -4,9 +4,11 @@
\alias{as.array.ZarrArray}
\title{S3 method for as.array}
\usage{
-\method{as.array}{ZarrArray}(obj)
+\method{as.array}{ZarrArray}(x, ...)
}
\arguments{
+\item{...}{not used}
+
\item{obj}{object}
}
\description{
diff --git a/man/figures/logo.png b/man/figures/logo.png
new file mode 100644
index 0000000..5173ffc
Binary files /dev/null and b/man/figures/logo.png differ
diff --git a/man/pizzarr_sample.Rd b/man/pizzarr_sample.Rd
new file mode 100644
index 0000000..3a85c2c
--- /dev/null
+++ b/man/pizzarr_sample.Rd
@@ -0,0 +1,34 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utils.R
+\name{pizzarr_sample}
+\alias{pizzarr_sample}
+\title{pizzarr demo data}
+\usage{
+pizzarr_sample(
+ dataset = NULL,
+ outdir = file.path(tempdir(TRUE), "pizzarr_sample")
+)
+}
+\arguments{
+\item{dataset}{character defining which demo dataset is desired,
+If NULL, all are returned}
+
+\item{outdir}{character directory path to store sample zarr stores}
+}
+\value{
+path to ready to use zarr store
+}
+\description{
+pizzarr demo data
+}
+\details{
+For directory stores, unzips the store to a temporary directory
+and returns the resulting path.
+}
+\examples{
+zarr_samples <- pizzarr_sample()
+
+#printing without system path for example
+gsub(tempdir(), "...", zarr_samples, fixed = TRUE)
+
+}
diff --git a/man/slice.Rd b/man/slice.Rd
index 4fc4109..fc2e974 100644
--- a/man/slice.Rd
+++ b/man/slice.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/slicing.R
\name{slice}
\alias{slice}
-\title{Shortcut for Slice$new() constructor.}
+\title{Convenience function for the internal Slice class constructor.}
\usage{
slice(start, stop = NA, step = NA, zero_based = FALSE)
}
@@ -19,5 +19,5 @@ slice(start, stop = NA, step = NA, zero_based = FALSE)
A Slice instance with the specified parameters.
}
\description{
-Shortcut for Slice$new() constructor.
+Convenience function for the internal Slice class constructor.
}
diff --git a/man/subset-.ZarrArray.Rd b/man/subset-.ZarrArray.Rd
index e5e5b15..95a410a 100644
--- a/man/subset-.ZarrArray.Rd
+++ b/man/subset-.ZarrArray.Rd
@@ -7,9 +7,7 @@
\method{[}{ZarrArray}(obj, ...) <- value
}
\arguments{
-\item{obj}{object}
-
-\item{...}{dots}
+\item{value}{array or ZarrArray}
}
\description{
S3 method for custom bracket assignment
diff --git a/man/zarr_create.Rd b/man/zarr_create.Rd
index 014f954..1508544 100644
--- a/man/zarr_create.Rd
+++ b/man/zarr_create.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/creation.R
\name{zarr_create}
\alias{zarr_create}
-\title{Create an array}
+\title{Create an empty array}
\usage{
zarr_create(
shape,
@@ -99,5 +99,5 @@ with checking the data of each chunk.}
ZarrArray
}
\description{
-Create an array
+Create an empty array
}
diff --git a/man/zarr_open_array.Rd b/man/zarr_open_array.Rd
index 18a4277..01c1e70 100644
--- a/man/zarr_open_array.Rd
+++ b/man/zarr_open_array.Rd
@@ -6,6 +6,7 @@
\usage{
zarr_open_array(
store = NA,
+ storage_options = NA,
mode = NA,
shape = NA,
chunks = TRUE,
@@ -29,6 +30,10 @@ zarr_open_array(
\item{store}{: MutableMapping or string
Store or path to directory in file system or name of zip file.}
+\item{storage_options}{: dict
+If using an fsspec URL to create the store, these will be passed to
+the backend implementation. Ignored otherwise.}
+
\item{mode}{: {'r', 'r+', 'a', 'w', 'w-'}, optional
Persistence mode: 'r' means read only (must exist); 'r+' means
read/write (must exist); 'a' means read/write (create if doesn't
diff --git a/man/zb_slice.Rd b/man/zb_slice.Rd
index 21093b6..f32517c 100644
--- a/man/zb_slice.Rd
+++ b/man/zb_slice.Rd
@@ -2,7 +2,8 @@
% Please edit documentation in R/slicing.R
\name{zb_slice}
\alias{zb_slice}
-\title{Shortcut for Slice$new() constructor with zero-based indexing and exclusive stop index.}
+\title{Convenience function for the internal Sliceclass constructor
+with zero-based indexing and exclusive stop index.}
\usage{
zb_slice(start, stop = NA, step = NA)
}
@@ -14,5 +15,6 @@ zb_slice(start, stop = NA, step = NA)
\item{step}{The step size.}
}
\description{
-Shortcut for Slice$new() constructor with zero-based indexing and exclusive stop index.
+Convenience function for the internal Sliceclass constructor
+with zero-based indexing and exclusive stop index.
}
diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml
index 357781c..79db12e 100644
--- a/pkgdown/_pkgdown.yml
+++ b/pkgdown/_pkgdown.yml
@@ -76,6 +76,7 @@ reference:
- as_scalar
- is_scalar
- is_key_error
+ - pizzarr_sample
- Dtype
diff --git a/tests/testthat/setup-utils.R b/tests/testthat/setup-utils.R
index d775204..26eda5a 100644
--- a/tests/testthat/setup-utils.R
+++ b/tests/testthat/setup-utils.R
@@ -4,3 +4,23 @@ setup({
teardown({
})
+
+zarr_volcano <- function() {
+ dir <- file.path(tempdir(TRUE), "volcano.zarr")
+
+ unlink(dir, recursive = TRUE, force = TRUE)
+
+ z <- DirectoryStore$new(dir)
+
+ a <- volcano
+
+ za <- zarr_create(dim(volcano), path = "volcano", store = z, overwrite = TRUE)
+
+ za$set_item("...", a)
+
+ g <- zarr_open_group(z)
+
+ g$get_attrs()$set_item("tile", "volcano")
+
+ g
+}
diff --git a/tests/testthat/test-compat.R b/tests/testthat/test-compat.R
index 8c62ef1..bb08796 100644
--- a/tests/testthat/test-compat.R
+++ b/tests/testthat/test-compat.R
@@ -2,7 +2,7 @@ library(pizzarr)
test_that("Can open Zarr group using convenience function", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample(file.path("fixtures", "v2", "data.zarr"))
g <- zarr_open_group(root)
a <- g$get_item("1d.contiguous.lz4.i2")
@@ -12,7 +12,7 @@ test_that("Can open Zarr group using convenience function", {
test_that("Can open Zarr group or array using convenience function", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
g <- zarr_open(root)
a <- zarr_open(root, path="1d.contiguous.lz4.i2")
@@ -22,7 +22,7 @@ test_that("Can open Zarr group or array using convenience function", {
test_that("Can open Zarr group and read a 1D 2-byte integer array with LZ4 compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -41,7 +41,7 @@ test_that("Can open Zarr group and read a 1D 2-byte integer array with LZ4 compr
test_that("Can open Zarr group and read a 1D 2-byte integer array with Zstd compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -60,7 +60,7 @@ test_that("Can open Zarr group and read a 1D 2-byte integer array with Zstd comp
test_that("Can open Zarr group and read a 1D 2-byte integer array with Blosc compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -88,7 +88,7 @@ test_that("Can open Zarr group and read a 1D 2-byte integer array with Blosc com
test_that("Can open Zarr group and read a 1D 2-byte integer array with Zlib compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -107,7 +107,7 @@ test_that("Can open Zarr group and read a 1D 2-byte integer array with Zlib comp
test_that("Can open Zarr group and read a 1D 2-byte integer array with no compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -126,7 +126,7 @@ test_that("Can open Zarr group and read a 1D 2-byte integer array with no compre
test_that("Can open Zarr group and read a 1D 4-byte integer array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -143,7 +143,7 @@ test_that("Can open Zarr group and read a 1D 4-byte integer array", {
test_that("Can open Zarr group and read a 1D 1-byte unsigned integer array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -160,7 +160,7 @@ test_that("Can open Zarr group and read a 1D 1-byte unsigned integer array", {
test_that("Can open Zarr group and read a 1D 4-byte float array, little endian", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -177,7 +177,7 @@ test_that("Can open Zarr group and read a 1D 4-byte float array, little endian",
test_that("Can open Zarr group and read a 1D 4-byte float array, big endian", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -194,7 +194,7 @@ test_that("Can open Zarr group and read a 1D 4-byte float array, big endian", {
test_that("Can open Zarr group and read a 1D 8-byte float array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -211,7 +211,7 @@ test_that("Can open Zarr group and read a 1D 8-byte float array", {
test_that("Can open Zarr group and read a 1D 2-byte float array, 2 chunks", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -228,7 +228,7 @@ test_that("Can open Zarr group and read a 1D 2-byte float array, 2 chunks", {
test_that("Can open Zarr group and read a 1D 2-byte float array, 2 chunks, ragged", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -245,7 +245,7 @@ test_that("Can open Zarr group and read a 1D 2-byte float array, 2 chunks, ragge
test_that("Can open Zarr group and read a 2D 2-byte integer array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -263,7 +263,7 @@ test_that("Can open Zarr group and read a 2D 2-byte integer array", {
test_that("Can open Zarr group and read a 2D 2-byte integer array, 2 chunks", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -281,7 +281,7 @@ test_that("Can open Zarr group and read a 2D 2-byte integer array, 2 chunks", {
test_that("Can open Zarr group and read a 2D 2-byte integer array, 2 chunks, ragged", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -301,7 +301,7 @@ test_that("Can open Zarr group and read a 2D 2-byte integer array, 2 chunks, rag
test_that("Can open Zarr group and read a 1D 1-byte boolean array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -318,7 +318,7 @@ test_that("Can open Zarr group and read a 1D 1-byte boolean array", {
test_that("Can open Zarr group and read a 1D S7 string array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -335,7 +335,7 @@ test_that("Can open Zarr group and read a 1D S7 string array", {
test_that("Can open Zarr group and read a 1D U7 string array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -352,7 +352,7 @@ test_that("Can open Zarr group and read a 1D U7 string array", {
test_that("Can open Zarr group and read a 1D U13 little endian string array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -369,7 +369,7 @@ test_that("Can open Zarr group and read a 1D U13 little endian string array", {
test_that("Can open Zarr group and read a 1D U13 big endian string array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -386,7 +386,7 @@ test_that("Can open Zarr group and read a 1D U13 big endian string array", {
test_that("Can open Zarr group and read a 2D U7 string array", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -403,7 +403,7 @@ test_that("Can open Zarr group and read a 2D U7 string array", {
test_that("Can open Zarr group and read a 1D VLen-UTF8 string array with no compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -420,7 +420,7 @@ test_that("Can open Zarr group and read a 1D VLen-UTF8 string array with no comp
test_that("Can open Zarr group and read a 1D VLen-UTF8 string array with Blosc compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -436,7 +436,7 @@ test_that("Can open Zarr group and read a 1D VLen-UTF8 string array with Blosc c
})
test_that("Can open Zarr group and read a 2D VLen-UTF8 string array with no compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -452,7 +452,7 @@ test_that("Can open Zarr group and read a 2D VLen-UTF8 string array with no comp
})
test_that("Can open Zarr group and read a 2D VLen-UTF8 string array with Blosc compression", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -468,9 +468,9 @@ test_that("Can open Zarr group and read a 2D VLen-UTF8 string array with Blosc c
})
test_that("DirectoryStore can listdir", {
- root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
expect_equal(store$listdir("1d.chunked.i2"), c(".zarray", "0", "1"))
-})
\ No newline at end of file
+})
diff --git a/tests/testthat/test-get.R b/tests/testthat/test-get.R
index 2f0a9cc..85dc935 100644
--- a/tests/testthat/test-get.R
+++ b/tests/testthat/test-get.R
@@ -16,7 +16,7 @@ test_that("get_basic_selection_zd", {
})
test_that("get_basic_selection_zd with anndataR IntScalar fixture", {
- root <- system.file("extdata", "fixtures", "v2", "example.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/example.zarr")
store <- DirectoryStore$new(root)
z <- zarr_open_array(store, path = "uns/IntScalar")
@@ -30,7 +30,7 @@ test_that("get_basic_selection_zd with anndataR IntScalar fixture", {
})
test_that("get_basic_selection_zd with anndataR StringScalar fixture", {
- root <- system.file("extdata", "fixtures", "v2", "example.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/example.zarr")
store <- DirectoryStore$new(root)
z <- zarr_open_array(store, path = "uns/StringScalar")
@@ -256,7 +256,7 @@ test_that("get_basic_selection_3d(one-based) - can get_item for three-dimensiona
})
test_that("Can read 2D string array", {
- root <- system.file("extdata", "fixtures", "v2", "example.zarr", package="pizzarr")
+ root <- pizzarr_sample("fixtures/v2/example.zarr")
store <- DirectoryStore$new(root)
z <- zarr_open_array(store, path = "uns/String2D")
nested_arr <- z$get_item("...")
diff --git a/tests/testthat/test-indexing-basic.R b/tests/testthat/test-indexing-basic.R
index 2fdf00c..e63b6b7 100644
--- a/tests/testthat/test-indexing-basic.R
+++ b/tests/testthat/test-indexing-basic.R
@@ -117,4 +117,26 @@ test_that("basic indexer for array that spans multiple chunks where shape is not
expect_equal(sdi2$dim_chunk_len, 3)
expect_equal(sdi2$num_items, 5)
expect_equal(sdi2$num_chunks, 4)
+})
+
+test_that("selection functionality", {
+
+ a <- zarr_volcano()$get_item("volcano")
+
+ sub_a <- a$get_item(list(slice(1, 10), "..."))
+
+ expect_equal(sub_a$shape, c(10, a$get_shape()[2]))
+
+ sub_a <- a$get_item(list(":", slice(1, 10)))
+
+ expect_equal(sub_a$shape, c(a$get_shape()[1], 10))
+
+ sub_a <- a$get_item(list(1, "..."))
+
+ expect_equal(sub_a$shape, c(1, a$get_shape()[2]))
+
+ sub_a <- a$get_item(list("...", slice(1, 10)))
+
+ expect_equal(sub_a$shape, c(a$get_shape()[1], 10))
+
})
\ No newline at end of file
diff --git a/tests/testthat/test-nested-array.R b/tests/testthat/test-nested-array.R
index cff115d..5532745 100644
--- a/tests/testthat/test-nested-array.R
+++ b/tests/testthat/test-nested-array.R
@@ -52,4 +52,50 @@ test_that("NestedArray can be set using list of zb_slices", {
python_sel <- na$get(list(zb_slice(0, 2), zb_slice(0, 3)))
expect_equal(python_sel$data, new_a)
+})
+
+test_that("zero_based_to_one_based", {
+
+ s <- list(slice(1, 11, 1))
+
+ expect_equal(zero_based_to_one_based(s, shape = c(20, 20)),
+ list(c(1:11)))
+
+ s <- list(slice(1, 11, 2))
+
+ expect_equal(zero_based_to_one_based(s, shape = c(20, 20)),
+ list(seq(1, 11, 2)))
+})
+
+test_that("set array values", {
+
+ d <- zarr_volcano()
+
+ a <- d$get_item("volcano")
+
+ vals <- a[1:10, 1:20]$as.array()
+
+ new_vals <- vals * 10
+
+ sub <- a[1:10, 1:20]
+
+ sub$set(list(slice(1,10), slice(1,20)), new_vals)
+
+ expect_equal(sub$as.array(),
+ new_vals)
+
+ # Should this be the case?!?
+ expect_error(a[1:10, 1:20]$set("...", new_vals),
+ "selection must be a list of slices")
+
+ a[1:10, 1:20]$set(list(slice(1,10), slice(1,20)), new_vals)
+
+ # it does not update the original array -- should it?
+ expect_equal(a[1:10, 1:20]$as.array(),
+ vals)
+
+ a$set_item(list(slice(1,10), slice(1,20)), new_vals)
+
+ expect_equal(a[1:10, 1:20]$as.array(),
+ new_vals)
})
\ No newline at end of file
diff --git a/tests/testthat/test-slice-indices.R b/tests/testthat/test-slice-indices.R
index ff5c515..3988df1 100644
--- a/tests/testthat/test-slice-indices.R
+++ b/tests/testthat/test-slice-indices.R
@@ -36,4 +36,14 @@ test_that("slice gets converted to zb_slice", {
expect_equal(s1$start, s2$start)
expect_equal(s1$stop, s2$stop)
expect_equal(s1$step, s2$step)
+})
+
+test_that("step size greater than 1", {
+ g <- zarr_volcano()
+
+ s <- slice(1, 21, 2)
+
+ d <- g$get_item("volcano")$get_item(list(s, s))$data
+
+ expect_equal(dim(d), c(11, 11))
})
\ No newline at end of file
diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R
index c0b1897..3a92b79 100644
--- a/tests/testthat/test-utils.R
+++ b/tests/testthat/test-utils.R
@@ -1,5 +1,19 @@
library(pizzarr)
+test_that("demo data", {
+
+ demo_data <- pizzarr_sample()
+
+ expect_true(all(dir.exists(demo_data)))
+
+ expect_true(all(grepl("zarr$", demo_data)))
+
+ expect_error(pizzarr_sample("borked"), "Dataset not found")
+
+ expect_true(grepl("bcsd.zarr", pizzarr_sample("bcsd")))
+
+})
+
test_that("create_zarray_meta does not throw error when simple dtype is valid", {
res <- create_zarray_meta(dtype = Dtype$new("|u1"), order = "C", fill_value = 0, dimension_separator = ".")
expect_equal(class(res$dtype)[[1]], "scalar")
@@ -193,4 +207,12 @@ test_that("get_list_product", {
list('C', 'y'),
list('D', 'y')
))
+})
+
+test_that("NaN in json", {
+ check <- try_fromJSON('{"name": NaN}')
+
+ expect_equal(check, list(name = NULL))
+
+ expect_warning(try_fromJSON("borked", "test warning"), "test warning")
})
\ No newline at end of file
diff --git a/vignettes/basics.Rmd b/vignettes/basics.Rmd
index 55c49d8..4e47eb3 100644
--- a/vignettes/basics.Rmd
+++ b/vignettes/basics.Rmd
@@ -64,7 +64,7 @@ print(a$get_shape())
## List arrays in a zarr root group
```{r}
-root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+root <- pizzarr_sample("fixtures/v2/data.zarr")
z <- zarr_open(root)
@@ -80,7 +80,7 @@ print(store$listdir())
## Open a ZarrArray from a DirectoryStore (convenience)
```{r}
-root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+root <- pizzarr_sample("fixtures/v2/data.zarr")
g <- zarr_open_group(root)
a <- g$get_item("1d.contiguous.lz4.i2")
@@ -91,7 +91,7 @@ print(a$get_shape())
## Open a ZarrArray from a DirectoryStore
```{r}
-root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
+root <- pizzarr_sample("fixtures/v2/data.zarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
@@ -103,7 +103,7 @@ print(a$get_shape())
## Get attributes from a root group and ZarrArray
```{r}
-root <- system.file("extdata", "dog.ome.zarr", package="pizzarr")
+root <- pizzarr_sample("dog.ome.zarr")
z <- zarr_open(root)
@@ -122,4 +122,4 @@ a <- z$get_item("4")
class(a)
a$get_attrs()$to_list()
-```
\ No newline at end of file
+```
diff --git a/vignettes/ome-ngff.Rmd b/vignettes/ome-ngff.Rmd
index cf5068f..08dee7e 100644
--- a/vignettes/ome-ngff.Rmd
+++ b/vignettes/ome-ngff.Rmd
@@ -21,7 +21,7 @@ install.packages("raster")
library(pizzarr)
# The path to the root of the OME-NGFF Zarr store.
-root <- system.file("extdata", "dog.ome.zarr", package="pizzarr")
+root <- pizzarr_sample("dog.ome.zarr")
# Open the OME-NGFF as a DirectoryStore.
store <- DirectoryStore$new(root)
diff --git a/vignettes/pizzarr.Rmd b/vignettes/pizzarr.Rmd
new file mode 100644
index 0000000..43e24e1
--- /dev/null
+++ b/vignettes/pizzarr.Rmd
@@ -0,0 +1,183 @@
+---
+title: "Getting Started"
+output: rmarkdown::html_vignette
+vignette: >
+ %\VignetteIndexEntry{Getting Started}
+ %\VignetteEngine{knitr::rmarkdown}
+ %\VignetteEncoding{UTF-8}
+---
+
+```{r, include = FALSE}
+ knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>",
+ out.width = "100%"
+)
+```
+
+# Introduction
+
+Pizzarr implements an object oriented zarr client library that represents zarr stores, groups, attributes, and arrays.
+
+For those not familiar with zarr, a "store" implies how the entire zarr dataset is... stored. e.g. in memory, on disk, or on the internet. A group is a container that may be in a hierarchy, it can contain group level attributes, arrays, and / or child groups. Attributes are key value pairs carried by both groups and attributes. Arrays are where the actual data reside and can be chunked and compressed in a variety of ways.
+
+When you encounter a zarr store, you would usually first look in the "root group" metadata and list the groups and arrays recursively to figure out what the store contains. From there, you might look at metadata associated with arrays and any child groups the store contains to figure out what they are or how you might want to work with them.
+
+Some zarr stores include what's known as "consolidated metadata". It is consolidated because all the metadata from all the groups and arrays in the store are consolidated into a single json file contained in the root group. This can be super convenient or even required if the store doesn't support "listing" like you do with `ls` at a terminal (http stores for example). The problem with consolidated metadata is that it can get out of sync with what the dataset actually contains, so it is usually created once a dataset is done and ready to be made "read only".
+
+# pizzarr classes:
+
+`Store` class: Implements a variety of ways to store zarr data. Is the container for all groups and arrays in a zarr dataset.
+`ZarrGroup` class: Supports getting and setting attributes of a group and creating groups and arrays within a group.
+`ZarrArray` class: Supports a variety of operations for getting and setting attributes and data from an array.
+`Attributes` class: Supports access to attributes carried by groups and arrays.
+`Codec`class: Supports encoding and decoding arrays according to the implemented compressor.
+`Dtype` class: Supports handling R data types as zarr codec compatible data types.
+
+# Core use cases:
+
+## Create stores, groups, and arrays
+
+An empty store can be created with one of the store implementations or by specifying
+the store type when creating a group or an array.
+
+```{r}
+library(pizzarr)
+
+# get an empty store to add to later
+mem_store <- MemoryStore$new()
+
+class(mem_store)
+
+# create a store in line when creating an empty array
+demo_array <- zarr_create(c(1,2,3), store = NA)
+
+demo_array_store <- demo_array$get_store()
+
+class(demo_array_store)
+
+demo_array_store$listdir()
+
+# or create a store when creating a group to contain arrays
+# notice that passing a path creates a directory store
+store_path <- file.path(tempdir(), "demo.zarr")
+
+demo_group <- zarr_create_group(store = store_path)
+
+demo_group_store <- demo_group$get_store()
+
+basename(demo_group_store$root)
+
+class(demo_group_store)
+
+demo_group_store$listdir()
+
+```
+## Set and get attributes
+
+We now have 1) an empty memory store, 2) an empty array in a memory store, and 3) a group defined within a directory store. Now we'll create a group using our existing empty memory store and add some attributes to it, retrieve them, and delete them.
+
+```{r}
+
+demo_mem_store_group <- zarr_create_group(mem_store)
+
+demo_mem_store_group$get_attrs()$key
+
+demo_mem_store_group$get_attrs()$set_item("this is", "an attribute")
+
+demo_mem_store_group$get_attrs()$to_list()
+
+demo_mem_store_group$get_attrs()$del_item("this is")
+
+demo_mem_store_group$get_attrs()$to_list()
+
+```
+Notice that we can do the same thing on arrays -- which can also carry attributes.
+
+```{r}
+
+demo_array_store$listdir()
+
+demo_array$get_attrs()$set_item("this is", "array metadata")
+
+demo_array$get_attrs()$to_list()
+
+# notice that when we added the item, our demo array store got a .zattrs
+demo_array_store$listdir()
+
+```
+## Set values of an array
+
+Now that we have the ability to create stores, groups, and arrays and know how to add attributes to groups and arrays, let's look at how to add data. For this, we'll use the directory store we created above.
+
+```{r}
+
+zarr_volcano <- zarr_create_array(volcano, # the R array classic
+ shape = dim(volcano),
+ store = demo_group_store, # the store we want the array in
+ path = "volcano") # the path we want the array stored in
+
+demo_group_store$listdir()
+
+zarr_volcano$get_shape()
+
+all.equal(zarr_volcano$as.array(),
+ volcano)
+
+```
+
+Now that we have an array in a zarr store, we can pull out subsets of it with pizzarr R6 methods or with the `S3` method for `[`.
+
+```{r}
+sub_zarr_volcano <- zarr_volcano$get_item(list(slice(1, 10), slice(1, 20)))
+
+all.equal(sub_zarr_volcano$as.array(),
+ volcano[1:10, 1:20])
+
+sub_zarr_volcano <- zarr_volcano[1:10, 1:20]
+
+class(sub_zarr_volcano)
+
+sub_zarr_volcano$shape
+
+all.equal(sub_zarr_volcano$as.array(),
+ volcano[1:10, 1:20])
+
+```
+
+Notice that we can also update the values of an array with the `set_item()` method.
+
+```{r}
+
+# this woll work once implemented?
+# zarr_volcano[1:10, 1:20] <- zarr_volcano[1:10, 1:20] * 10
+
+zarr_volcano$set_item(list(slice(1, 10), slice(1, 20)),
+ zarr_volcano[1:10, 1:20]$as.array() * 10)
+
+```
+
+The `slice()` function is great but the `selection` input to the `get_item()` and `set_item()` methods can also accept other kinds of inputs. Namely, scalars to select single indices and a couple of special character strings.
+
+`"..."` selects everything else. It can be used to the left, right, or in the middle of the selection list but can only be used once.
+`":"` selects everything along a single dimension and can be used as many times as needed.
+
+```{r}
+
+sub_zarr_volcano <- zarr_volcano$get_item(list(1, "..."))
+
+sub_zarr_volcano$shape
+
+sub_zarr_volcano <- zarr_volcano$get_item(list(":", 1))
+
+sub_zarr_volcano$shape
+
+sub_zarr_volcano <- zarr_volcano$get_item(list("..."))
+
+sub_zarr_volcano$shape
+
+sub_zarr_volcano <- zarr_volcano$get_item(list(slice(1, 20, 2), slice(1, 10, 1)))
+
+sub_zarr_volcano$shape
+
+```
\ No newline at end of file