A bundle_set is a collection of bundle objects, designed for
multi-subject or multi-session studies where each element represents one
subject's (or session's) tractogram. It stores three compartments:
@bundles— a list of bundle objects (names are optional).@bundle_data— a named list of per-bundle vectors (any type), each of length \(B\) (the number of bundles). Values common to all bundles may be lifted here automatically from the individual bundles'@bundle_dataslots at construction time.@set_data— a named list of scalars (length-1 values, any type) holding set-level metadata.
Arguments
- bundles
A list of bundle objects (may be named or unnamed).
- bundle_data
A named list of per-bundle vectors of length B. If not supplied, any
@bundle_datakeys common to all bundles are lifted automatically.- set_data
A named list of set-level scalar metadata.
Methods for standard generics
The following methods are defined for bundle_set objects:
format(x, ...): Returns a styled character string.print(x, ...): Prints the formatted string to the console and invisibly returnsx.length(x): Returns the number of bundles.x[[i]]: Extracts thei-th (or named) bundle from the set, with set-level@bundle_datapushed back into the bundle.x[i]: Returns a new bundle_set containing only the selected bundles, with@set_dataand the subset of@bundle_datapreserved.
Additional properties
@n_bundlesAn integer scalar giving the number of bundles in the set (read-only).
@bundle_attributesA character vector of the names of the per-bundle attributes stored at the set level (read-only).
@set_attributesA character vector of the names of the set-level attributes (read-only).
Examples
sl <- streamline(points = cbind(X = 1:5, Y = 1:5, Z = 1:5))
b1 <- bundle(
streamlines = list(sl),
bundle_data = list(subject = "sub-01")
)
b2 <- bundle(
streamlines = list(sl),
bundle_data = list(subject = "sub-02")
)
# subject is common across bundles and lifted to bundle_set@bundle_data
bs <- bundle_set(bundles = list("sub-01" = b1, "sub-02" = b2))
bs@n_bundles # 2
#> [1] 2
bs@bundle_attributes # "subject"
#> [1] "subject" "id_from_input_names"
bs@bundle_data$subject # c("sub-01", "sub-02")
#> [1] "sub-01" "sub-02"
