struct: Create a structure.

View source: R/standalone-struct-list.R

structR Documentation

Create a structure.

Description

Create a structure.

Usage

struct(..., .class = NULL, .attr = list())

is.struct(x, .class = NULL)

as.struct(x, .class)

## S3 method for class 'struct'
as.list(x, ...)

is.struct_list(x, .class = NULL)

Arguments

...

a set of named values to use in the structure. or an unnamed list of 'struct's of the same type

.class

the class of the nested list

.attr

attributes to assign to the 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.

Methods (by generic)

  • as.list(struct): Make 'struct' into plain list

Functions

  • is.struct(): Check is a 'struct'

  • as.struct(): Cast to a 'struct'

  • is.struct_list(): is a list of 'structs'?

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
x[[1]] # is a struct of length 1

# e = struct(.class="test")
try(struct())

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)


terminological/ggrrr documentation built on June 15, 2024, 6:35 a.m.