grimbough / Rarr

A simple native R reader for Zarr Arrays
https://bioconductor.org/packages/Rarr/
MIT License
34 stars 5 forks source link

`write_zarr_array` is not nested structure #2

Open giovp opened 1 year ago

giovp commented 1 year ago

HI,

after writing with write_zarr_array the content of the folder is the following

❯ lls new.zarrnew.zarr
.rw-r--r--@ 2.8M giovanni.palla 28 Apr 14:08 0.0.0

although I would have expected the following?

❯ tree
.
└── 0
    └── 0
        └── 0
            └── 0

yet the roundtrip as in the examples work, so not sure maybe expected behaviour?

grimbough commented 1 year ago

Hi @giovp

I think you should be able to use the dimension_separator argument to specify this e.g.

library(Rarr)

new_zarr_array <- file.path(tempdir(), "integer.zarr")
x <- array(1:50, dim = c(10, 5))
write_zarr_array(
  x = x, 
  zarr_array_path = new_zarr_array,
  chunk_dim = c(2, 5),
  dimension_separator = "/"
)

list.files(new_zarr_array, recursive = TRUE, full.names = TRUE)
#> [1] "/tmp/RtmpovandC/integer.zarr/0/0" "/tmp/RtmpovandC/integer.zarr/1/0"
#> [3] "/tmp/RtmpovandC/integer.zarr/2/0" "/tmp/RtmpovandC/integer.zarr/3/0"
#> [5] "/tmp/RtmpovandC/integer.zarr/4/0"

The Zarr spec says the following:

If the value is not set, then the default MUST be assumed to be ".", leading to chunk keys of the form “0.0”.

which is why the default is "."