Learn R Programming

broadcast (version 0.1.7)

cast_dim2flat: Cast Dimensional List into a Flattened List

Description

cast_dim2flat() casts a dimensional list (i.e. recursive array) into a flat list (i.e. recursive vector), but with names that indicate the original dimensional positions of the elements.

Primary purpose for this function is to facilitate printing or summarizing dimensional lists.

Usage

cast_dim2flat(x, ...)

# S3 method for default cast_dim2flat(x, ...)

Value

A flattened list, with names that indicate the original dimensional positions of the elements.


Arguments

x

a list

...

further arguments passed to or from methods.

See Also

broadcast_casting

Examples

Run this code

x <- array(
  sample(list(letters, month.name, 1:10 ~ "foo"), prod(4:2), TRUE),
  dim = 4:2,
  dimnames = list(NULL, LETTERS[1:3], c("x", "y"))
)


# summarizing ====
summary(x) # dimensional information is lost

# In the following instances, dimensional position info is retained:
cast_dim2flat(x) |> summary()

cast_dim2flat(x[1:3, 1:2, 2, drop = FALSE]) |> summary()

cast_dim2flat(x[1:3, 1:2, 2, drop = TRUE]) |> summary()


# printing ====
print(x) # too compact
cast_dim2flat(x) |> print() # much less compact


Run the code above in your browser using DataLab