tests/testthat/test-read_dti_tcktsf.R

testthat::test_that('read.dti.track() loads valid files in TSF und TCK formats', {
  testthat::skip_on_cran();
  freesurferformats::download_opt_data();
  dwi_dir = freesurferformats::get_opt_data_filepath("dwi");

  # TCK
  fp_tck = file.path(dwi_dir, 'tracks.tck');
  testthat::skip_if_not(file.exists(fp_tck));
  TCK = freesurferformats::read.dti.tck(fp_tck);

  testthat::expect_type(TCK, 'list');
  expect_named(TCK, c('header', 'tracks'));

  testthat::expect_equal(TCK$header$id, 'mrtrix tracks');
  testthat::expect_true(TCK$header$count > 0);

  testthat::expect_true(is.list(TCK$tracks));
  testthat::expect_equal(length(TCK$tracks), TCK$header$max_num_tracks);
  testthat::expect_true(all(is.finite(unlist(TCK$tracks, recursive=FALSE, use.names=FALSE))));

  # TSF
  fp_tsf = file.path(dwi_dir, 'tracks.tsf');
  testthat::skip_if_not(file.exists(fp_tsf));
  TSF = freesurferformats::read.dti.tsf(fp_tsf);

  testthat::expect_type(TSF, 'list');
  testthat::expect_named(TSF, c('header', 'scalars'));

  testthat::expect_equal(TSF$header$id, 'mrtrix track scalars');
  testthat::expect_true(TSF$header$count > 0);

  testthat::expect_true(is.numeric(TSF$scalars$merged));
  testthat::expect_true(all(is.finite(TSF$scalars$merged)));

  testthat::expect_true(is.list(TSF$scalars$scalar_list));
  testthat::expect_equal(length(TSF$scalars$merged), sum(lengths(TSF$scalars$scalar_list)));
})

Try the freesurferformats package in your browser

Any scripts or data that you put into this service are public.

freesurferformats documentation built on July 8, 2026, 5:08 p.m.