15  anylist

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 and the class 'list' defined in package base, both shipped with R version 4.5.2 (2025-10-31). Listing 15.1 summarizes the S3 methods for the class 'anylist' in the spatstat.* family of packages,

Listing 15.1: S3 methods spatstat.*::*.anylist
Code
suppressPackageStartupMessages(library(spatstat))
.S3methods(class = 'anylist', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = grepl(pattern = '^spatstat\\.', x = from))
#                       visible             from       generic  isS4
# [.anylist                TRUE    spatstat.geom             [ FALSE
# [<-.anylist              TRUE    spatstat.geom           [<- FALSE
# as.hyperframe.anylist    TRUE    spatstat.geom as.hyperframe FALSE
# collapse.anylist         TRUE spatstat.explore      collapse FALSE
# plot.anylist             TRUE    spatstat.geom          plot FALSE
# pool.anylist             TRUE spatstat.explore          pool FALSE
# print.anylist            TRUE    spatstat.geom         print FALSE
# summary.anylist          TRUE    spatstat.geom       summary FALSE

The examples in Chapter 15 require

library(groupedHyperframe)
search path & loadedNamespaces on author’s computer
search()
#  [1] ".GlobalEnv"                "package:groupedHyperframe" "package:stats"             "package:graphics"          "package:grDevices"         "package:utils"             "package:datasets"         
#  [8] "package:methods"           "Autoloads"                 "package:base"
loadedNamespaces() |> sort.int()
#  [1] "abind"             "base"              "cli"               "cluster"           "codetools"         "compiler"          "datasets"          "deldir"            "digest"           
# [10] "doParallel"        "dplyr"             "evaluate"          "farver"            "fastmap"           "fastmatrix"        "foreach"           "generics"          "geomtextpath"     
# [19] "GET"               "ggplot2"           "glue"              "goftest"           "graphics"          "grDevices"         "grid"              "gridExtra"         "groupedHyperframe"
# [28] "gtable"            "htmltools"         "htmlwidgets"       "iterators"         "jsonlite"          "knitr"             "lattice"           "lifecycle"         "magrittr"         
# [37] "Matrix"            "matrixStats"       "methods"           "nlme"              "otel"              "parallel"          "patchwork"         "pillar"            "pkgconfig"        
# [46] "polyclip"          "pracma"            "R6"                "RColorBrewer"      "rlang"             "rmarkdown"         "rstudioapi"        "S7"                "scales"           
# [55] "SpatialPack"       "spatstat.data"     "spatstat.explore"  "spatstat.geom"     "spatstat.random"   "spatstat.sparse"   "spatstat.univar"   "spatstat.utils"    "stats"            
# [64] "systemfonts"       "tensor"            "textshaping"       "tibble"            "tidyselect"        "tools"             "utils"             "vctrs"             "viridisLite"      
# [73] "xfun"              "yaml"

Table 15.1 summarizes the S3 methods for the class 'anylist' in package groupedHyperframe (v0.3.2.20251225),

Table 15.1: S3 methods groupedHyperframe::*.anylist (v0.3.2.20251225)
visible generic isS4
attr_.anylist TRUE groupedHyperframe::attr_ FALSE
global_envelope_test_.anylist TRUE groupedHyperframe::global_envelope_test_ FALSE
kerndens.anylist TRUE groupedHyperframe::kerndens FALSE
quantile.anylist TRUE stats::quantile FALSE

15.1 Kernel Density Estimates of Numeric Vectors

The S3 method kerndens.anylist() (Section 33.1, Table 33.2) finds the kernel density estimates of each numeric-vector member of an anylist.

Listing 15.2

Listing 15.2: Example: function kerndens.anylist()
set.seed(11); spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(3e2L)
) |> 
  kerndens(n = 8L)
# [[1]]
# [1] 0.0001485149 0.0279242695 0.2154613160 0.3923521927 0.3012886913 0.1122736307 0.0254082139 0.0002006779
# 
# [[2]]
# [1] 1.079725e-04 4.811775e-02 1.650921e-01 3.967321e-01 3.138711e-01 1.112372e-01 1.968247e-02 6.978272e-05

Listing 15.3 showcases the exception handling of a non-numeric anylist, the hypercolumn Kovesi$values (Section 10.14).

Listing 15.3: Exception: function kerndens.anylist(), no numeric-vector member
spatstat.data::Kovesi$values |> 
  kerndens() |>
  is.null() |> stopifnot()

15.2 Quantile of Numeric Vectors

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

Listing 15.4: Example: function quantile.anylist()
set.seed(11); spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(3e2L)
) |> 
  quantile()
# [[1]]
#         0%        25%        50%        75%       100% 
# -2.1867814 -0.8209852 -0.1868264  0.5014134  2.3396931 
# 
# [[2]]
#           0%          25%          50%          75%         100% 
# -2.384519560 -0.570462185  0.007376154  0.662883606  2.771382086

Listing 15.5 showcases the exception handling of a non-numeric anylist, the hypercolumn Kovesi$values (Section 10.14).

Listing 15.5: Exception: function quantile.anylist(), no numeric-vector member
spatstat.data::Kovesi$values |> 
  quantile() |>
  is.null() |> stopifnot()

15.3 Global Envelope Test

The S3 generic function global_envelope_test_() is a batch process of the function GET::global_envelope_test() (Myllymäki and Mrkvička 2024, v1.0.7). Package groupedHyperframe (v0.3.2.20251225) implements the following S3 methods (Table 15.2),

Table 15.2: S3 methods of groupedHyperframe::global_envelope_test_ (v0.3.2.20251225)
visible isS4
global_envelope_test_.anylist TRUE FALSE
global_envelope_test_.hyperframe TRUE FALSE

The S3 method global_envelope_test_.anylist()

Examples of the S3 method global_envelope_test_.anylist() are Listing 37.24 and Listing 37.25.

15.4 Attributes per Element

The S3 generic function attr_() extracts specified attribute per element. Package groupedHyperframe (v0.3.2.20251225) implements the following S3 methods (Table 15.3),

Table 15.3: S3 methods of groupedHyperframe::attr_ (v0.3.2.20251225)
visible isS4
attr_.anylist TRUE FALSE
attr_.hyperframe TRUE FALSE

The S3 generic function attr_.anylist() extracts specified attribute per element of an anylist.

Listing 15.6 finds the 'class'-attribute per point-pattern in the point-pattern-list ('ppplist', Chapter 37) btb.extra (Section 10.6).

Listing 15.6: Example: function attr_.anylist()
spatstat.data::btb.extra |>
  attr_(which = 'class', exact = TRUE)
# full:
# [1] "ppp"
# 
# standard:
# [1] "ppp"

15.5 Split

Section 15.5 is intended as an educational piece for beginners to R version 4.5.2 (2025-10-31) and package spatstat.geom (v3.6.1.16). This section does not discuss the functionality of package groupedHyperframe (v0.3.2.20251225).

The default method 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 spatstat.geom::`[.anylist` (v3.6.1.16).

Listing 15.7 splits a spatial-object list (solist, Chapter 39) vesicles.extra (Section 10.22) into a list-of-solist.

Listing 15.7: Review: function base::split.default() on solist
spatstat.data::vesicles.extra |>
  split.default(f = factor(c('a', 'a', 'b', 'b'))) |> 
  lapply(FUN = class)
# $a
# [1] "solist"  "anylist" "listof"  "list"   
# 
# $b
# [1] "solist"  "anylist" "listof"  "list"

Listing 15.8 splits a pixel-image-object list (imlist, Chapter 29) gorillas.extra (Section 10.12) into a list-of-imlist.

Listing 15.8: Review: function base::split.default() on imlist
spatstat.data::gorillas.extra |>
  split.default(f = factor(c('a', 'a', 'b', 'b', 'c', 'c', 'c'))) |> 
  lapply(FUN = class)
# $a
# [1] "imlist"  "solist"  "anylist" "listof"  "list"   
# 
# $b
# [1] "imlist"  "solist"  "anylist" "listof"  "list"   
# 
# $c
# [1] "imlist"  "solist"  "anylist" "listof"  "list"

Listing 15.9 splits a point-pattern-object list (ppplist, Chapter 37) waterstriders (Section 10.23) into a list-of-ppplist.

Listing 15.9: Review: function base::split.default() on ppplist
spatstat.data::waterstriders |>
  split.default(f = factor(c('a', 'a', 'b'))) |> 
  lapply(FUN = class)
# $a
# [1] "ppplist" "solist"  "anylist" "listof"  "list"   
# 
# $b
# [1] "ppplist" "solist"  "anylist" "listof"  "list"