On 01/10/2021 6:14 p.m., Reed A. Cartwright wrote:
I'm rethinking the interface of a package, specifically how external binary
data is formatted for use in R. I can't decide if it is better to use
attributes to store metadata or use a list to hold the main data and
metadata as separate elements.

Is the object like some other common R object? You say it's a 16x16x16 array of integers. Is there an advantage to treating it *exactly* like that, so x[1,2,3] gives an integer? Then put the other stuff in attributes.

Is it weird enough that x[1,2,3] *needs* to look at the other attributes to know what to return? Does it never make sense to do regular operations on the object, as though it really was 16x16x16 array of integers? Then make it a list of different components, and spend the time to define methods to handle any operations that do make sense.

Both approaches are possible; you want to choose the one that is easiest, and most maintainable.

Duncan Murdoch


Here's is what one datatype currently looks like:

List of 2
  $ : int [1:16, 1:16, 1:16] 9 9 9 9 10 10 1 1 14 14 ...
   ..- attr(*, "palette")=List of 16
  [snip]
  $ : int [1:16, 1:16, 1:16] 1 1 1 1 1 1 1 1 1 1 ...
   ..- attr(*, "palette")=List of 2
  [snip]
   - attr(*, "offset")= int 3

It's a list of two 16x16x16 arrays of integers. Each array has its own
"palette" attribute. Each value in the array refers to a specific element
of the palette. In addition the entire list has an offset attribute.

I am considering alternative strategies for representing this data, and I
would like any opinions on which style is recommended and why?

List of 3
  $ index  :List of 2
   ..$ : int [1:16, 1:16, 1:16] 9 9 9 9 10 10 1 1 14 14 ...
   ..$ : int [1:16, 1:16, 1:16] 1 1 1 1 1 1 1 1 1 1 ...
  $ palette:List of 2
   ..$ :List of 16
   ..$ :LIST of 2
  $ offset : int 3

or

List of 2
  $ :List of 2
   ..$ index: int [1:16, 1:16, 1:16] 9 9 9 9 10 10 1 1 14 14 ...
   ..$ palette:List of 16
  $ : List of 2
  ..$ index : int [1:16, 1:16, 1:16] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ palette : List of 2
  - attr(*, "offset")= int 3

Thanks.

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to