18  data.frame

Function base::data.frame() creates a data frame, i.e., an R object of S3 class 'data.frame'. Listing 18.1 summarizes the S3 methods for the class 'data.frame' in the spatstat.* family of packages,

Listing 18.1: S3 methods spatstat.*::*.data.frame
Code
suppressPackageStartupMessages(library(spatstat))
.S3methods(class = 'data.frame', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = grepl(pattern = '^spatstat\\.', x = from))
#                          visible             from       generic  isS4
# as.fv.data.frame            TRUE spatstat.explore         as.fv FALSE
# as.hyperframe.data.frame    TRUE    spatstat.geom as.hyperframe FALSE
# as.im.data.frame            TRUE    spatstat.geom         as.im FALSE
# as.owin.data.frame          TRUE    spatstat.geom       as.owin FALSE
# as.ppp.data.frame           TRUE    spatstat.geom        as.ppp FALSE
# as.psp.data.frame           TRUE    spatstat.geom        as.psp FALSE
# multiplicity.data.frame     TRUE    spatstat.geom  multiplicity FALSE
# uniquemap.data.frame        TRUE  spatstat.univar     uniquemap FALSE

The examples in Chapter 18 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 18.1 summarizes the S3 methods for the class 'data.frame' in package groupedHyperframe (v0.3.2.20251225),

Table 18.1: S3 methods groupedHyperframe::*.data.frame (v0.3.2.20251225)
visible from generic isS4
as.groupedHyperframe.data.frame TRUE groupedHyperframe groupedHyperframe::as.groupedHyperframe FALSE

18.1 Create groupedHyperframe

The S3 generic function as.groupedHyperframe() creates a grouped hyper data frame (groupedHyperframe, Chapter 25). Package groupedHyperframe (v0.3.2.20251225) implements the following S3 methods (Table 18.2),

Table 18.2: S3 methods of groupedHyperframe::as.groupedHyperframe (v0.3.2.20251225)
visible isS4
as.groupedHyperframe.data.frame TRUE FALSE
as.groupedHyperframe.groupedData TRUE FALSE
as.groupedHyperframe.hyperframe TRUE FALSE

The S3 method as.groupedHyperframe.data.frame() converts a data frame with substantial amount of duplicated information into a grouped hyper data frame.

In Chapter 2, Listing 2.1, Listing 2.2,

  1. inspects the input data frame lung0 (Listing 2.1) by the user-specified (nested) grouping structure, e.g., image_id nested in patient_id;
  2. identifies the input data frame column(s) with non-identical elements within the lowest group, e.g., the numeric column lung0$hladr and the factor column lung0$phenotype;
  3. converts these column(s) into the hypercolumn(s) of the output grouped hyper data frame (Listing 2.2), e.g., the numeric-hypercolumn lung_g$hladr and the factor-hypercolumn lung_g$phenotype. Each row of the output grouped hyper data frame (Listing 2.2) represents the lowest group of the nested grouping structure.