11  anylist

The examples in Chapter 11 require that the search path contains the following namespaces,

library(groupedHyperframe)

Function spatstat.geom::anylist() creates a list of objects of any type, i.e., an R object of S3 class 'anylist', which inherits from the class 'listof' defined in package stats shipped with R version 4.5.1 (2025-06-13). In addition to the existing S3 method dispatches spatstat.geom::*.anylist (v3.6.0.3, Listing 11.1) and spatstat.explore::*.anylist (v3.5.3.3, Listing 11.2),

Listing 11.1: Existing S3 method dispatches spatstat.geom::*.anylist
Code
suppressPackageStartupMessages(library(spatstat.geom))
methods(class = 'anylist', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = from == 'spatstat.geom')
#                       visible          from       generic  isS4
# [.anylist                TRUE spatstat.geom             [ FALSE
# [<-.anylist              TRUE spatstat.geom           [<- FALSE
# as.hyperframe.anylist    TRUE spatstat.geom as.hyperframe FALSE
# plot.anylist             TRUE spatstat.geom          plot FALSE
# print.anylist            TRUE spatstat.geom         print FALSE
# summary.anylist          TRUE spatstat.geom       summary FALSE
Listing 11.2: Existing S3 method dispatches spatstat.explore::*.anylist
Code
suppressPackageStartupMessages(library(spatstat.explore))
methods(class = 'anylist', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = from == 'spatstat.explore')
#                  visible             from  generic  isS4
# collapse.anylist    TRUE spatstat.explore collapse FALSE
# pool.anylist        TRUE spatstat.explore     pool FALSE

Package groupedHyperframe (v0.3.0.20251020) implements more S3 method dispatches to the class 'anylist' (Listing 11.3, Table 11.1),

Listing 11.3: Table: S3 method dispatches groupedHyperframe::*.anylist
Code
methods2kable(class = 'anylist', package = 'groupedHyperframe', all.names = TRUE)
Table 11.1: S3 method dispatches groupedHyperframe::*.anylist (v0.3.0.20251020)
visible from generic isS4
kerndens.anylist TRUE groupedHyperframe groupedHyperframe::kerndens FALSE
quantile.anylist TRUE groupedHyperframe stats::quantile FALSE

11.1 Kernel Density Estimates of numeric-vectors

The S3 method dispatch kerndens.anylist() finds the kernel densitys of each numeric-vector member of an anylist.

Example: function kerndens.anylist()
spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(1e2L)
) |> 
  kerndens(n = 8L)
# [[1]]
# [1] 0.0001161367 0.0111770062 0.0738221691 0.2798497894 0.3092550415 0.2036384279 0.0430319969 0.0001607981
# 
# [[2]]
# [1] 0.0001295201 0.0199265325 0.1009740112 0.2883741979 0.3739260486 0.1672157755 0.0317010996 0.0001506271
Exception: function kerndens.anylist(), no numeric-vector member
spatstat.data::Kovesi$values |>
  sapply(FUN = class) |>
  unique.default()
# [1] "character"
spatstat.data::Kovesi$values |> 
  kerndens() |>
  is.null()
# [1] TRUE

11.2 Quantile of numeric-vectors

The S3 method dispatch quantile.anylist() finds the quantiles of each numeric-vector member of an anylist.

Example: function quantile.anylist()
spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(1e2L)
) |> 
  quantile()
# [[1]]
#         0%        25%        50%        75%       100% 
# -2.3645586 -0.5335547 -0.1156894  0.4684773  1.8108271 
# 
# [[2]]
#          0%         25%         50%         75%        100% 
# -2.37859630 -0.67601565  0.05162509  0.68971708  2.59814245
Exception: function quantile.anylist(), no numeric-vector member
spatstat.data::Kovesi$values |>
  sapply(FUN = class) |>
  unique.default()
# [1] "character"
spatstat.data::Kovesi$values |> 
  quantile() |>
  is.null()
# [1] TRUE

11.3 Split

Section 11.3 is intended as an educational handbook for beginners to R version 4.5.1 (2025-06-13) and package spatstat.geom (v3.6.0.3). This section does not discuss the functionality of package groupedHyperframe (v0.3.0.20251020).

The default dispatch of the S3 generic function base::split() splits an anylist into a list of anylist. This feature is made possible by the magic of the S3 method dispatch spatstat.geom::`[.anylist`.

Listing 11.4 splits a spatial-object list (solist, Chapter 25) vesicles.extra (Section 8.20) into a list of solist.

Listing 11.4: Review: function base::split.default() on solist
v1 = spatstat.data::vesicles.extra |>
  split.default(f = factor(c('a', 'a', 'b', 'b')))
v2 = spatstat.data::vesicles.extra |>
  split(f = factor(c('a', 'a', 'b', 'b')))
stopifnot(identical(v1, v2))

Listing 11.5 splits a pixel-image-object list (imlist, Chapter 20) gorillas.extra (Section 8.12) into a list of imlist.

Listing 11.5: Review: function base::split.default() on imlist
g1 = spatstat.data::gorillas.extra |>
  split.default(f = factor(c('a', 'a', 'b', 'b', 'c', 'c', 'c')))
g2 = spatstat.data::gorillas.extra |>
  split(f = factor(c('a', 'a', 'b', 'b', 'c', 'c', 'c')))
stopifnot(identical(g1, g2))

Listing 11.6 splits a point-pattern-object list (ppplist, Chapter 24) waterstriders (Section 8.21) into a list of ppplist.

Listing 11.6: Review: function base::split.default() on ppplist
w1 = spatstat.data::waterstriders |>
  split.default(f = factor(c('a', 'a', 'b')))
w2 = spatstat.data::waterstriders |>
  split(f = factor(c('a', 'a', 'b')))
stopifnot(identical(w1, w2))