Provides a unified input-output interface for reading and writing bundles — collections of 3-D polylines (streamlines) reconstructed by fibre-tracking algorithms applied to diffusion MRI data. Supported formats include VTK (.vtk), VTP (.vtp), medInria FDS (.fds), MRtrix TCK/TSF (.tck/.tsf), and TrackVis TRK (.trk), with additional formats accessible via the 'DIPY' Python library through 'reticulate'. Bundles are represented in R using the S7 classes defined in the 'fiber' package: a single tract (class 'streamline') stores its coordinates, per-point scalar attributes, and per-streamline scalar attributes in separate, typed slots; a collection of tracts (class 'bundle') wraps a list of streamlines together with optional bundle-level metadata. VTK support is provided at compile time by the 'rvtk' package, which supplies pre-compiled VTK libraries and headers so that no manual VTK installation is required on most platforms.

The riot (R Input/Output for
Tractography) package provides an R interface for importing and
exporting tractography data to and from R. Currently supported
importing formats are:
.vtk and .vtp files;.fds files;.tck/.tsf files;.trk
files; and,.trx,
DIPY .dpy, and .fib files through the
‘DIPY’ Python library.The package reads tractography data into S7 objects defined by the {fiber} package:
streamline — a single fibre tract stored in three typed slots:
@points (an $n \times 3$ matrix with columns X, Y, Z),
@point_data (a named list of per-point numeric vectors,
e.g. diffusion metrics sampled at every point), and @streamline_data
(a named list of per-streamline scalar attributes).bundle — an ordered collection of streamline objects in
@streamlines, plus optional bundle-level metadata in @bundle_data.read_bundle() returns a streamline when the file contains a single
tract and a bundle otherwise. The optional bundle_data argument lets
you attach a named list of bundle-level metadata (e.g. subject ID,
hemisphere, or affine transform) directly at import time: the list is
stored in the @bundle_data slot of the returned bundle.
The package also allows to write bundles back into the following exporting formats:
.vtk and .vtp files; or,.fds files;.trk, .tck, .trx, .fib, and .dpy files through the ‘DIPY’
Python library (requires a reference image).A guided tour of the package is available in the vignette("riot")
vignette, and the internal design is described in the developer-oriented
vignette("riot-api") vignette.
You can install the released version of riot from CRAN with:
install.packages("riot")
Alternatively you can install the development version of riot from GitHub with:
# install.packages("remotes")
remotes::install_github("tractoverse/riot")
library(riot)
.vtk and .vtp filesuf_left_vtk <- read_bundle(system.file(
"extdata",
"UF_left.vtk",
package = "riot"
))
uf_left_vtk
#>
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#>
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#>
uf_left_vtp <- read_bundle(system.file(
"extdata",
"UF_left.vtp",
package = "riot"
))
uf_left_vtp
#>
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#>
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#>
.fds filesuf_left_fds <- read_bundle(system.file(
"extdata",
"UF_left.fds",
package = "riot"
))
uf_left_fds
#>
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#>
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#>
.tck/.tsf filesaf_left_tck <- read_bundle(system.file(
"extdata",
"AF_left.tck",
package = "riot"
))
af_left_tck
#>
#> ── Object of class `fiber::bundle()` with 5000 streamlines and [8–54] points per streamline. ──
#>
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#>
.trk filescc_mid_trk <- read_bundle(system.file(
"extdata",
"CCMid.trk",
package = "riot"
))
cc_mid_trk
#>
#> ── Object of class `fiber::bundle()` with 525 streamlines and [29–270] points per streamline. ──
#>
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#>
bundle_datauf_left_meta <- read_bundle(
system.file("extdata", "UF_left.vtk", package = "riot"),
bundle_data = list(subject = "sub-01", hemisphere = "left")
)
uf_left_meta@bundle_data
#> $subject
#> [1] "sub-01"
#>
#> $hemisphere
#> [1] "left"
riot relies on the fiber
package for the S7 classes streamline and bundle that represent
tractography data in R, as well as the constructors, predicates, and
geometry methods that operate on them. riot does not depend on
S7 directly.
Since version 1.2.0, riot delegates all VTK linkage to the rvtk infrastructure package. VTK is not a system requirement: neither for riot nor for rvtk. At install time, rvtk searches for a pre-installed VTK in the following order:
VTK_DIR environment variable (highest priority).brew install vtk).pkg-config — macOS and Linux./usr, /usr/local) — Linux.mingw-w64-ucrt-x86_64-vtk for UCRT64) — Windows.If no pre-installed VTK is found, rvtk automatically downloads a pre-compiled static or shared VTK build from its GitHub releases, so no manual VTK installation is ever required.
riot bundles TinyXML-2.
tinyxml2.cpp has been modified to avoid the use of stdout and
printf as per Writing R Extensions manual recommendations because
R has its own input/output mechanism for writing to the console.
The authors would like to thank Tim Schäfer, the author of the freesurferformats package, for his helpful code to read MRtrix and TrackVis tractography file formats.