riot riot website

R-CMD-check Codecov test coverage pkgdown CRAN status

Overview

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:

The package reads tractography data into S7 objects defined by the {fiber} package:

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:

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.

Installation

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")

Example

library(riot)

Native VTK .vtk and .vtp files

uf_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
#> 

medInria .fds files

uf_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
#> 

MRtrix .tck/.tsf files

af_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
#> 

TrackVis .trk files

cc_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
#> 

Attaching bundle-level metadata with bundle_data

uf_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"

Dependencies

fiber

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.

VTK

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:

  1. VTK_DIR environment variable (highest priority).
  2. Homebrew — macOS only (brew install vtk).
  3. pkg-config — macOS and Linux.
  4. Well-known system prefix paths (/usr, /usr/local) — Linux.
  5. Rtools42+ pacman package for the active MSYS2 environment (e.g. 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.

TinyXML-2

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.

Acknowledgements

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.