43  vectorlist from anylist

ImportantDisclaimer

These packages (Note 1) are a one-person project undergoing rapid evolution. Backward compatibility (per Hadley Wickham) is provided as a courtesy rather than a guarantee.

Until further notice, these packages should

  • not be used as a basis for research grant applications,
  • not be cited as an actively maintained tool in a peer-reviewed manuscript,
  • not be used to support or fulfill requirements for pursuing an academic degree.

In addition, work primarily based on these packages (Note 1) should not be presented at academic conferences or similar scholarly venues.

Furthermore, a person’s ability to use these packages (Note 1) does not necessarily imply an understanding of their underlying mechanisms. Accordingly, demonstration of their use alone should not be considered sufficient evidence of expertise, nor should it be credited as a basis for academic promotion or advancement.

These statements do not apply to the contributors (Tip 1) to these packages (Note 1) with respect to their specific contributions.

These statements do not apply when the maintainer of these packages (Note 1), Tingting Zhan, is credited as the first author, the lead author, and/or the corresponding author in a peer-reviewed manuscript, or as the Principal Investigator or Co-Principal Investigator in a research grant application and/or a final research progress report.

These statements are advisory in nature and do not modify or restrict the rights granted under the GNU General Public License https://www.r-project.org/Licenses/.

Note

The examples in Chapter 43 require

library(groupedHyperframe)

Package groupedHyperframe (v0.4.0, GPL-2) defines a derived S3 class 'vectorlist', for vector-list, which inherits from the classes 'anylist' (Chapter 15), 'listof' and 'list' and is assigned with additional attributes,

Table 43.1 summarizes the S3 methods for the class 'vectorlist' in package groupedHyperframe (v0.4.0, GPL-2),

Table 43.1: S3 methods groupedHyperframe::*.vectorlist (v0.4.0)
visible generic isS4
print.vectorlist FALSE base::print FALSE
t.vectorlist FALSE base::t FALSE

43.1 Creation & Print

The function as.vectorlist() inspects whether the input qualifies as a vector-list (Section 43.2), and if true, appends the derived class 'vectorlist' to the returned value.

The S3 method print.vectorlist() prints the vital information of a vector-list.

Listing 43.1 converts the hypercolumn Kovesi$values (Section 10.16) into a character vector-list and prints its vital information.

Listing 43.1: Data: a vectorlist object Kovesi_v
spatstat.data::Kovesi$values |>
  as.vectorlist(mode = 'character')
# A 'vectorlist' of 41 vectors 
# Storage Mode: character 
# Individual Vector Length: 256

Listing 43.2 creates a toy numeric vector-list toy_vecL and prints its vital information. Listing 43.3 prints each of the numeric-vector members in the vector-list toy_vecL.

Listing 43.2: Data: a toy numeric vectorlist
set.seed(12); toy_vecL = replicate(n = 5L, expr = rnorm(n = 6L), simplify = FALSE) |> 
  as.vectorlist(mode = 'numeric')
toy_vecL
# A 'vectorlist' of 5 vectors 
# Storage Mode: numeric 
# Individual Vector Length: 6
Listing 43.3: Review: function print.default() on vectorlist
toy_vecL |>
  print.default()
# [[1]]
# [1] -1.4805676  1.5771695 -0.9567445 -0.9200052 -1.9976421 -0.2722960
# 
# [[2]]
# [1] -0.3153487 -0.6282552 -0.1064639  0.4280148 -0.7777196 -1.2938823
# 
# [[3]]
# [1] -0.77956651  0.01195176 -0.15241624 -0.70346425  1.18887916  0.34051227
# 
# [[4]]
# [1]  0.5069682 -0.2933051  0.2236414  2.0072015  1.0119791 -0.3024592
# 
# [[5]]
# [1] -1.0252448 -0.2673848 -0.1991057  0.1311226  0.1457999  0.3620647
# 
# attr(,"class")
# [1] "vectorlist" "anylist"    "listof"     "list"      
# attr(,"mode")
# [1] "numeric"

43.2 Validity

The function is.vectorlist() inspects whether all elements of an anylist (Chapter 15)

The hypercolumn Kovesi$values (Section 10.16) qualifies as a 'character' vector-list (Listing 43.4), but not as a 'numeric' vector-list (Listing 43.5).

Listing 43.4: Example: function is.vectorlist()
spatstat.data::Kovesi$values |>
  is.vectorlist(mode = 'character') |>
  stopifnot()
Listing 43.5: Example: function is.vectorlist()
spatstat.data::Kovesi$values |>
  is.vectorlist(mode = 'numeric')
# [1] FALSE

43.3 Transpose

The S3 method t.vectorlist() transposes a vector-list into another vector-list, with the length and lengths of the input swapped. Table 43.2 explains the rational of using the S3 generic function t() (R version 4.5.3 (2026-03-11)).

Table 43.2: Rational of “Transpose”
base:::t.default() t.vectorlist()
Input & Output matrix vectorlist
Swaps ncol & nrow length & lengths

Listing 43.6 transposes the vector-list in Listing 43.1.

Listing 43.6: Example: function t.vectorlist()
Kovesi_v_t = spatstat.data::Kovesi$values |>
  as.vectorlist(mode = 'character') |> 
  t()
Kovesi_v_t
# A 'vectorlist' of 256 vectors 
# Storage Mode: character 
# Individual Vector Length: 41

The motivation of the derived class 'vectorlist' and the S3 method t.vectorlist() is that calling the S3 method with.hyperframe() (v3.7.3, GPL (>= 2)) repeatedly (Listing 43.7) is slow.

Listing 43.7: Review: function with.hyperframe() (Listing 43.6)
Code
spatstat.data::Kovesi |> 
  spatstat.geom::with.hyperframe(expr = values[1L]) |>
  identical(y = Kovesi_v_t[[1L]]) |>
  stopifnot()
spatstat.data::Kovesi |> 
  spatstat.geom::with.hyperframe(expr = values[2L]) |>
  identical(y = Kovesi_v_t[[2L]]) |>
  stopifnot()
spatstat.data::Kovesi |> 
  spatstat.geom::with.hyperframe(expr = values[256L]) |>
  identical(y = Kovesi_v_t[[256L]]) |>
  stopifnot()

The derived class 'vectorlist' is not supported as a hypercolumn in a hyper data frame (Chapter 26) as of package spatstat.geom v3.7.3, GPL (>= 2). Listing 43.8 calls the S3 method t.vectorlist() explicitly as a workaround before package spatstat.geom (ever) supports the class 'vectorlist'.

Listing 43.8: Workaround: without derived class 'vectorlist' (Listing 43.6)
spatstat.data::Kovesi$values |>
  groupedHyperframe:::t.vectorlist() |>
  identical(y = Kovesi_v_t) |>
  stopifnot()