keller-mark / pizzarr

Slice into Zarr arrays in R 🍕
https://keller-mark.github.io/pizzarr/
Other
29 stars 3 forks source link

Error in writing character arrays with arbitrary size #112

Open Artur-man opened 2 months ago

Artur-man commented 2 months ago

Describe the bug

There seems to be an error when writing zarr arrays with character elements and arbitrary shape. I traced it here by debugging but couldn't really figure out:

https://github.com/keller-mark/pizzarr/blob/f84355d2708c22dc6e703f3cdd83d218221b352a/R/zarr-array.R#L633-L648

To Reproduce

mat <- array(rep("text", 545*689), dim = c(545, 689))
zarr.array <- pizzarr::zarr_open(store = "data/string_test.zarr", mode = "w")
zarr.array$create_dataset(name = "assay", data = mat, shape = dim(mat), dtype = "<S20")

Error

Error in buf[offset_i_start:offset_i_stop] <- raw_vec_i : 
  replacement has length zero

Environment:

Artur-man commented 2 months ago

This doesn't seem to be the case with other sizes:

mat <- array(rep("text", 100*100), dim = c(100, 100))
zarr.array <- pizzarr::zarr_open(store = "data/string_test.zarr", mode = "w")
zarr.array$create_dataset(name = "assay", data = mat, shape = dim(mat), dtype = "<S20")
<ZarrArray>
  Public:
    [: function (...) 
    [<-: function (...) 
    append: function (data, axis = 0) 

Also the problem doesn't occur with numeric arrays:

mat <- array(sample(1:20, 545*689, replace = TRUE), dim = c(545, 689))
zarr.array <- pizzarr::zarr_open(store = "data/pizzarr_test.zarr", mode = "w")
zarr.array$create_dataset(name = "assay", data = mat, shape = dim(mat))
<ZarrArray>
  Public:
    [: function (...) 
    [<-: function (...) 
    append: function (data, axis = 0)