[R-pkg-devel] Lists vs Attributes

Reed A. Cartwright r@c@rtwr|ght @end|ng |rom gm@||@com
Sat Oct 2 00:14:43 CEST 2021


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.

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]]



More information about the R-package-devel mailing list