Skip to contents

a5_cell_to_children(), a5_grid_disk() and a5_spherical_cap() return an a5_cell_list when called with simplify = FALSE: a vctrs::list_of() holding one a5_cell vector per input, usable as a list column. It behaves as any list: lengths() gives the number of cells per input, [[ extracts one element, and tidyr::unnest() expands it to one row per cell.

Usage

as_a5_cell_list(x)

# S3 method for class 'a5_cell_list'
unlist(x, recursive = TRUE, use.names = TRUE)

Arguments

x

An a5_cell_list, or for as_a5_cell_list() a list of a5_cell vectors.

recursive, use.names

Ignored.

Value

unlist() returns an a5_cell vector.

Details

unlist() concatenates the elements into a single a5_cell vector, equivalent to vctrs::list_unchop(). Without this method base unlist() would descend into the raw byte fields of the record and return a meaningless raw vector. The recursive and use.names arguments are accepted for compatibility and ignored.

as_a5_cell_list() wraps a plain list of a5_cell vectors (for example the output of lapply()) so that unlist() works on it. Elements that are hex strings are converted; NULL elements become empty.

Examples

cells <- a5_lonlat_to_cell(c(-3.19, 0), c(55.95, 0), resolution = 5)
lst <- a5_cell_to_children(cells, simplify = FALSE)
lengths(lst)
#> [1] 4 4
unlist(lst)
#> <a5_cell[8]>
#> [1] 6314800000000000 6315800000000000 6316800000000000 6317800000000000
#> [5] 4f08800000000000 4f09800000000000 4f0a800000000000 4f0b800000000000

# lapply() produces a plain list, on which base unlist() would return raw
# bytes; wrap it first.
plain <- lapply(seq_along(cells), function(i) a5_cell_to_children(cells[i]))
unlist(as_a5_cell_list(plain))
#> <a5_cell[8]>
#> [1] 6314800000000000 6315800000000000 6316800000000000 6317800000000000
#> [5] 4f08800000000000 4f09800000000000 4f0a800000000000 4f0b800000000000