Create a structure.
Value
Usually a length one struct_list
with a single struct
item with class .class
and attributes .attr
. If a list of struct
s is provided then it will be
longer than 1.
Functions
is.struct()
: Check is astruct
as.struct()
: Cast to astruct
is.struct_list()
: is a list ofstructs
?
Examples
x = struct(a=1,b=2,c=1:3,.class="test")
format.test = function(x,...) {sprintf("\"%d/%d [%d-%d]\"", x$a, x$b, min(x$c), max(x$c))}
x # is a struct_list of length 1
#> test(a, b, c)
#> 1, 2, 1, 2, 3
x[[1]] # is a struct of length 1
#> 1, 2, 1, 2, 3
# e = struct(.class="test")
try(struct())
#> Error : Item is not a `struct_list`, a `struct` or a uniform list of `structs`.
x =
struct(
struct(a=1,b=2,c=1:3,.class="test"),
struct(a=2,b=3,c=4:5,.class="test")
)
tmp = lapply(1:10, function(x) struct(a=x,b=3,c=4:5,.class="test"))
struct(tmp)
#> test(a, b, c)
#> 1, 3, 4, 5 2, 3, 4, 5 3, 3, 4, 5 4, 3, 4, 5 5, 3, 4, 5 6, 3, 4, 5 7, 3, 4, 5 8, 3, 4, 5 9, 3, 4, 5 10, 3, 4, 5