Skip to content

Indexing in more than 2 dimensions in R? #259

Description

@marciolegal

Hi,
I'm looking to use Tile DB as a replacement for NetCDF to store tridimensional (row, col, time) data in R. I'm currently facing three issues in R.

The first issue is trying to write data from a tileDB array using 3-dimensional R arrays.
For example, I changed Example 1 to include an extra dimension "time", using the same attributes:

dom <- tiledb_domain(dims = list(
  tiledb_dim("rows", c(1L, 10L), 10L, "INT32"),
  tiledb_dim("cols", c(1L, 5L), 5L, "INT32"),
  tiledb_dim("time", c(1L, 2L), 2L, "INT32")))
schema <- tiledb_array_schema(dom, attrs = c(tiledb_attr("a", type = "INT32"),
                                             tiledb_attr("b", type = "FLOAT64"),
                                             tiledb_attr("c", type = "CHAR", ncells = NA_integer_)))

I can't just pass a list of tridimentional R arrays to the tileDB array. It only recognizes the first 2 dimensions of the R array:

data <- list(a=array(seq(1:100), dim = c(10,5, 2)),
             b=array(as.double(seq(101,by=0.5,length=100)), dim = c(10,5,2)),
             c=array(rep(c(letters[1:26], "brs", "asdf", LETTERS[1:22]), 2), dim = c(10,5,2)))
A <- tiledb_array(uri = uri, as.data.frame = TRUE, query_layout = "ROW_MAJOR")
A[] <- data

The above throws:

Error in libtiledb_query_submit(qryptr) :
[TileDB::Writer] Error: Buffer sizes check failed; Invalid number of cells given for attribute 'c' (50 != 100)

If I instead just pass a list of two-dimensional arrays with 100 values, it works.

Is it not currently possible to feed the n-dimentional tileDB array with a n-dimensional R array?

The second issue is that I also can't access the values using tridimensional indexing. After feeding my A array with a list of 2-dimensional R arrays as said above, A[1:2, 1:2, 1] gives:

"rows" "cols" "time" "a" "b" "c"
1 1 1 1 101 "a"
1 1 2 51 126 "a"
1 2 1 11 106 "k"
1 2 2 61 131 "k"
2 1 1 2 101.5 "b"
2 1 2 52 126.5 "b"
2 2 1 12 106.5 "l"
2 2 2 62 131.5 "l"

When I expected to see only data from time 1. Instead it is returning all times. In the R docs it says the third argument is ignored. So how do we query multidimensional arrays in R?

The third problem arises when trying to write the data using the query:

qry <- tiledb_query_set_buffer(qry, "c", data[["c"]])

throws:

Error in libtiledb_query_set_buffer(query@ptr, attr, buffer) :
Invalid attribute buffer type for attribute 'c': STRSXP

It seems that character arrays are not supported in this way. Works fine when using A[]<-data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions