A bundle is an ordered collection of streamline objects representing a
tractogram or white-matter bundle. It stores two compartments:
@streamlines— a list of streamline objects.@bundle_data— a named list of bundle-level metadata (arbitrary R objects, e.g. the affine transform used during tracking).
Arguments
- streamlines
A list of streamline objects.
- bundle_data
A named list of bundle-level metadata.
Methods for standard generics
The following methods are defined for bundle objects:
format(x, ...): Returns a compact character string such as<bundle [2 streamlines | 10–20 pts/streamline]>.print(x, ...): Prints the formatted string to the console and invisibly returnsx.length(x): Returns the number of streamlines (equivalent tox@n_streamlines).x[[i]]: Extracts thei-th streamline from the bundle.x[i]: Returns a new bundle containing only the selected streamlines, preserving@bundle_data.
Additional properties
@n_streamlinesAn integer scalar giving the number of streamlines in the bundle (read-only).
@bundle_attributesA character vector of the names of the bundle-level attributes (read-only).
Examples
pts <- matrix(runif(15), ncol = 3, dimnames = list(NULL, c("X", "Y", "Z")))
sl <- streamline(points = pts)
b <- bundle(streamlines = list(sl))
b@n_streamlines # 1
#> [1] 1
b@bundle_attributes # NULL (no bundle-level attributes)
#> NULL
# bundle_data is stored
b2 <- bundle(
streamlines = list(sl),
bundle_data = list(subject = "sub-01")
)
b2@bundle_data$subject # "sub-01"
#> [1] "sub-01"
# format(), print(), length() and indexing methods
format(b2)
#> [1] "<bundle [1 streamlines | 5–5 pts/streamline] | bundle: subject>"
print(b2)
#> <bundle [1 streamlines | 5–5 pts/streamline] | bundle: subject>
length(b2) # 1
#> [1] 1
b2[[1]] # first streamline
#> <streamline [5 pts]>
# subsetting preserves bundle_data
pts2 <- matrix(runif(15), ncol = 3, dimnames = list(NULL, c("X", "Y", "Z")))
sl2 <- streamline(points = pts2)
b3 <- bundle(streamlines = list(sl, sl2), bundle_data = list(subject = "sub-01"))
b3[1]@n_streamlines # 1, bundle_data preserved
#> [1] 1