14  anylist

Function spatstat.geom::anylist() (v3.7.0.6) 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 14.1 summarizes the S3 methods for the class 'anylist' in the spatstat.* family of packages,

Listing 14.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 14 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"    "splines"          
# [64] "stats"             "survival"          "systemfonts"       "tensor"            "textshaping"       "tibble"            "tidyselect"        "tools"             "utils"            
# [73] "vctrs"             "viridisLite"       "xfun"              "yaml"

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

Table 14.1: S3 methods groupedHyperframe::*.anylist (v0.3.4)
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

14.1 Kernel Density Estimates of Numeric Vectors

The S3 method kerndens.anylist() (Section 32.1, Table 32.2)

  • applies the S3 method kerndens.numeric() (Section 32.1) to each numeric-vector member of the input anylist;
  • returns a numeric vector-list (vectorlist, Chapter 42).

Listing 14.2 finds the kernel density estimates of each of the two numeric-vector members of an anylist.

Listing 14.2: Example: function kerndens.anylist()
set.seed(11); spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(3e2L)
) |> 
  kerndens(n = 8L) |>
  print.default()
# [[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
# 
# attr(,"class")
# [1] "vectorlist" "anylist"    "listof"     "list"      
# attr(,"mode")
# [1] "numeric"

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

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

14.2 Quantile of Numeric Vectors

The S3 method quantile.anylist()

Listing 14.4 finds the quantiles of each of the two numeric-vector members of an anylist.

Listing 14.4: Example: function quantile.anylist()
set.seed(11); spatstat.geom::anylist(
  rnorm(1e2L),
  rnorm(3e2L)
) |> 
  quantile() |>
  print.default()
# [[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 
# 
# attr(,"class")
# [1] "vectorlist" "anylist"    "listof"     "list"      
# attr(,"mode")
# [1] "numeric"

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

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

14.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.4) implements the following S3 methods (Table 14.2),

Table 14.2: S3 methods of groupedHyperframe::global_envelope_test_ (v0.3.4)
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 36.24 and Listing 36.25.

14.4 Attributes per Element

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

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

The S3 generic function attr_.anylist()

  • extracts specified attribute per element of the input anylist;
  • returns an anylist.

Listing 14.6 finds the 'class'-attribute per point-pattern in the point-pattern-list ('ppplist', Chapter 36) btb.extra (Section 9.6).

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

14.5 Split

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

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.7.0.6).

Listing 14.7 splits a spatial-object list (solist, Chapter 38) vesicles.extra (Section 9.25) into a list-of-solist.

Listing 14.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 14.8 splits a pixel-image-object list (imlist, Chapter 28) gorillas.extra (Section 9.14) into a list-of-imlist.

Listing 14.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 14.9 splits a point-pattern-object list (ppplist, Chapter 36) waterstriders (Section 9.26) into a list-of-ppplist.

Listing 14.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"