Convert a tidytensor into a nested list of tensors, nested down to level specified in rank. If flatten = TRUE, returns a flattens the structure to a list of tensors (not nested).

# S3 method for tidytensor
as.list(x, rank = 1, flatten = TRUE, state = NULL, ...)

Arguments

x

the tidytensor to convert.

rank

an indicator of the rank defining the contained tensors.

flatten

whether to return a nested list (FALSE) or a flattened list (TRUE).

state

an internally used parameter for tracking build state-do not set manually.

...

additional arguments passed to methods (unusued).

Value

a list.

Details

The state parameter is for internal use, and needn't be set during normal usage.

Examples

# Three tidytensors of the same shape
t1 <- as.tidytensor(array(100 * 1:(3 * 4 * 5), dim = c(3, 4, 5)))
ranknames(t1) <- c("sample", "row", "col")
l1 <- as.list(t1)
str(l1)
#> List of 3
#>  $ sample [1, , ], shape (4, 5): 'tidytensor' num [1:4, 1:5] 100 400 700 1000 1300 1600 1900 2200 2500 2800 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ row: chr [1:4] NA NA NA NA
#>   .. ..$ col: chr [1:5] NA NA NA NA ...
#>   ..- attr(*, "index_string")= chr "[1, , ]"
#>   ..- attr(*, "shape_string")= chr "(4, 5)"
#>  $ sample [2, , ], shape (4, 5): 'tidytensor' num [1:4, 1:5] 200 500 800 1100 1400 1700 2000 2300 2600 2900 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ row: chr [1:4] NA NA NA NA
#>   .. ..$ col: chr [1:5] NA NA NA NA ...
#>   ..- attr(*, "index_string")= chr "[2, , ]"
#>   ..- attr(*, "shape_string")= chr "(4, 5)"
#>  $ sample [3, , ], shape (4, 5): 'tidytensor' num [1:4, 1:5] 300 600 900 1200 1500 1800 2100 2400 2700 3000 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ row: chr [1:4] NA NA NA NA
#>   .. ..$ col: chr [1:5] NA NA NA NA ...
#>   ..- attr(*, "index_string")= chr "[3, , ]"
#>   ..- attr(*, "shape_string")= chr "(4, 5)"