| Title: | R Inputs/Outputs for Tractography |
| Version: | 1.2.0 |
| Description: | 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| LinkingTo: | cpp11, |
| Imports: | cli, fiber, fs, rlang, rvtk (≥ 0.2.0) |
| Suggests: | knitr, pkgdown, quarto, reticulate, tinytest |
| VignetteBuilder: | quarto |
| SystemRequirements: | Python (>= 3.7) with the 'dipy' package is optional; required only for TRX, FIB, and DPY bundle formats. |
| URL: | https://github.com/tractoverse/riot, https://tractoverse.github.io/riot/ |
| BugReports: | https://github.com/tractoverse/riot/issues |
| Config/roxygen2/version: | 8.1.1 |
| Config/roxygen2/markdown: | TRUE |
| NeedsCompilation: | yes |
| Packaged: | 2026-11-26 09:31:11 UTC; stamm-a |
| Author: | Aymeric Stamm |
| Maintainer: | Aymeric Stamm <aymeric.stamm@cnrs.fr> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-26 14:10:02 UTC |
Convert a bundle (or streamline) to a flat named list for the C++ writers
Description
Reconstructs the X, Y, Z, PointId, StreamlineId columns (plus any
extra per-point attribute columns and per-streamline attributes broadcast to
all points) expected by WriteVTK(), WriteVTP(), and WriteFDS().
Usage
bundle_to_flat_list(x)
Arguments
x |
A bundle or streamline. |
Value
A named list suitable for passing to the C++ writer functions.
Convert a flat named list (C++ output) to a streamline or bundle
Description
The input is the named list returned by ReadVTK(), ReadVTP(), or
ReadFDS(), which has at minimum columns "X", "Y", "Z",
"PointId", and "StreamlineId". Columns named in streamline_cols are
treated as per-streamline attributes: one value is stored per streamline
(taken from the first occurrence in each group rather than broadcast).
All remaining extra columns are treated as per-point attributes.
Usage
flat_list_to_bundle(lst, streamline_cols = character(0L))
Arguments
lst |
A named list with at least the columns |
streamline_cols |
Character vector of column names to store as
per-streamline data. Defaults to |
Details
Returns a streamline when the data contain exactly one streamline, otherwise a bundle.
Value
A streamline or bundle.
Import bundles into R
Description
This is the go-to function to import bundles into R. Based on both VTK and DIPY, we currently
support eight different formats detailed in the documentation of input argument file.
Usage
read_bundle(file, reference_file = NULL, bundle_data = list())
Arguments
file |
A string specifying the path to the file containing the tractography data. Currently supported files are: |
reference_file |
A string specifying the path to a reference image file. This is only required
when importing |
bundle_data |
A named list of bundle-level metadata to store in the |
Value
A bundle object when the file contains multiple
streamlines, or a streamline object when it contains
exactly one. Each streamline stores its coordinates as an
n x 3 numeric matrix in the @points slot (columns "X", "Y",
"Z", one row per point along the tract). Additional per-point scalar
attributes, when present in the source file, appear in the
@point_data slot, and per-streamline attributes in the
@streamline_data slot.
When a bundle is returned and bundle_data is non-empty, its @bundle_data
slot is populated with the supplied list.
See Also
write_bundle() to export bundles from R.
Examples
uf_left_vtk <- read_bundle(system.file("extdata", "UF_left.vtk", package = "riot"))
# Attach bundle-level metadata
uf_left_vtk2 <- read_bundle(
system.file("extdata", "UF_left.vtk", package = "riot"),
bundle_data = list(subject = "sub-01", hemisphere = "left")
)
uf_left_vtk2@bundle_data
Export bundles from R
Description
This function exports a bundle stored as a bundle object
to a file in one of the supported formats. Supported formats include VTK
(.vtk), VTP (.vtp), FDS (.fds), TRK (.trk), TCK (.tck), TRX
(.trx), FIB (.fib), and DPY (.dpy). For formats that require a
reference image (such as TRX, FIB, and DPY), the user must provide the path
to a reference image file.
Usage
write_bundle(x, file, reference_file = NULL)
Arguments
x |
A bundle object. |
file |
A string specifying the path to the file containing the tractography data. Currently supported files are: |
reference_file |
A string specifying the path to a reference image file. This is only required
when importing |
Details
Warning: we rely on DIPY to provide support to save bundles in .trk, .trx, .tck, .dpy
and .fib formats. Among these formats, only .trk and .trx formats are able to keep track of
additional attributes assigned to either streamlines or points.
Value
The input bundle (invisibly) so that the function can be used in pipes.
See Also
read_bundle() to import bundles into R.
Examples
uf_left <- read_bundle(system.file("extdata", "UF_left.vtp", package = "riot"))
## Not run:
out <- fs::file_temp(ext = ".vtp")
write_bundle(uf_left, file = out)
## End(Not run)