Running ‘testthat.R’ [10s/15s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(freesurferformats)
  > 
  > test_check("freesurferformats")
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  freesurferformats
   --- call from context --- 
  write.fs.mgh(new_copy, ret_orig$data, vox2ras_matrix = ret_orig$header$vox2ras_matrix, 
      mr_params = ret_orig$header$mr_params)
   --- call from argument --- 
  if (!class(vox2ras_matrix) == "matrix") {
      stop("The 'vox2ras_matrix' argument must be a matrix.")
  }
   --- R stacktrace ---
  where 1 at testthat/test-read-fs-mgh.R#100: write.fs.mgh(new_copy, ret_orig$data, vox2ras_matrix = ret_orig$header$vox2ras_matrix, 
      mr_params = ret_orig$header$mr_params)
  where 2: eval(code, test_env)
  where 3: eval(code, test_env)
  where 4: withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error)
  where 5: doTryCatch(return(expr), name, parentenv, handler)
  where 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 7: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 10: tryCatchList(expr, classes, parentenv, handlers)
  where 11: tryCatch(withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error), error = handle_fatal, 
      skip = function(e) {
      })
  where 12: test_code(desc, code, env = parent.frame())
  where 13 at testthat/test-read-fs-mgh.R#94: test_that("A real MGH can be read, rewritten, read again, and the data and header are preserved as expected.", 
      {
          brain_image = system.file("extdata", "brain.mgz", package = "freesurferformats", 
              mustWork = TRUE)
          ret_orig = read.fs.mgh(brain_image, with_header = TRUE)
          expect_equal(class(ret_orig), "list")
          new_copy = tempfile(fileext = "mgz")
          write.fs.mgh(new_copy, ret_orig$data, vox2ras_matrix = ret_orig$header$vox2ras_matrix, 
              mr_params = ret_orig$header$mr_params)
          ret = read.fs.mgh(new_copy, with_header = TRUE)
          header = ret$header
          expect_equal(class(header), "list")
          expect_equal(header$dtype, 1)
          expect_equal(header$dof, 0)
          expect_equal(header$ras_good_flag, 1)
          expect_equal(length(header$internal$delta), 3)
          expect_equal(header$internal$delta, c(1, 1, 1), tolerance = 0.01)
          expect_equal(length(header$internal$Mdc), 9)
          expect_equal(header$internal$Mdc, matrix(c(-1, 0, 0, 
              0, 0, -1, 0, 1, 0), nrow = 3), tolerance = 0.01)
          expect_equal(length(header$internal$D), 9)
          expect_equal(length(header$internal$Pcrs_c), 3)
          expect_equal(length(header$internal$Pxyz_0), 3)
          expect_equal(header$internal$Pxyz_c, c(-0.5, 29.4, -48.9), 
              tolerance = 0.01)
          expect_equal(header$voldim, c(256, 256, 256, 1))
          expect_equal(length(header$has_mr_params), 1)
          expect_equal(length(header$mr_params), 4)
          expect_equal(header$mr_params, c(2300, 0.15708, 2.01, 
              900), tolerance = 0.01)
          expect_equal(header$vox2ras_matrix, matrix(c(-1, 0, 0, 
              0, 0, 0, -1, 0, 0, 1, 0, 0, 127.5, -98.6273, 79.0953, 
              1), nrow = 4, byrow = FALSE), tolerance = 0.01)
          vd = ret$data
          expect_equal(class(vd), "array")
          expect_equal(length(dim(vd)), 4)
          expect_equal(dim(vd), c(256, 256, 256, 1))
          expect_equal(vd[80, 80, 80, 1], 110)
          expect_equal(vd[100, 100, 100, 1], 77)
          expect_equal(vd[100, 100, 80, 1], 105)
      })
  where 14: eval(code, test_env)
  where 15: eval(code, test_env)
  where 16: withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error)
  where 17: doTryCatch(return(expr), name, parentenv, handler)
  where 18: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 19: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 22: tryCatchList(expr, classes, parentenv, handlers)
  where 23: tryCatch(withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error), error = handle_fatal, 
      skip = function(e) {
      })
  where 24: test_code(NULL, exprs, env)
  where 25: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 26: force(code)
  where 27: doWithOneRestart(return(expr), restart)
  where 28: withOneRestart(expr, restarts[[1L]])
  where 29: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 30: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter, 
      {
          reporter$start_file(basename(path))
          lister$start_file(basename(path))
          source_file(path, new.env(parent = env), chdir = TRUE, 
              wrap = wrap)
          reporter$.end_context()
          reporter$end_file()
      })
  where 31: FUN(X[[i]], ...)
  where 32: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 33: force(code)
  where 34: doWithOneRestart(return(expr), restart)
  where 35: withOneRestart(expr, restarts[[1L]])
  where 36: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 37: with_reporter(reporter = current_reporter, results <- lapply(paths, 
      test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE, 
      load_helpers = FALSE, wrap = wrap))
  where 38: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 39: test_dir(path = test_path, reporter = reporter, env = env, filter = filter, 
      ..., stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, 
      wrap = wrap)
  where 40: test_package_dir(package = package, test_path = test_path, filter = filter, 
      reporter = reporter, ..., stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 41: test_check("freesurferformats")
  
   --- value of length: 2 type: logical ---
  [1] FALSE  TRUE
   --- function from context --- 
  function (filepath, data, vox2ras_matrix = NULL, mr_params = c(0, 
      0, 0, 0)) 
  {
      if (!class(data) == "array") {
          if (class(data) == "numeric" || class(data) == "matrix") {
              data = array(data, dim = c(length(data), 1, 1, 1))
          }
          else {
              stop("The 'data' argument must be an array, a vector or a matrix.")
          }
      }
      if (length(mr_params) != 4) {
          stop(sprintf("The mr_params must be a vector of length 4 but length is %d.", 
              length(mr_params)))
      }
      if (length(vox2ras_matrix) == 0) {
          ras_flag = 0
      }
      else {
          if (!class(vox2ras_matrix) == "matrix") {
              stop("The 'vox2ras_matrix' argument must be a matrix.")
          }
          if (length(vox2ras_matrix) != 16 || nrow(vox2ras_matrix) != 
              4) {
              stop(sprintf("The 'vox2ras_matrix' argument must be a 4x4 matrix of length 16, but length is %d and nrow is %d.", 
                  length(vox2ras_matrix), nrow(vox2ras_matrix)))
          }
          ras_flag = 1
      }
      if (guess.filename.is.gzipped(filepath, gz_entensions = c(".mgz"))) {
          fh = gzfile(filepath, "wb")
      }
      else {
          fh = file(filepath, "wb", blocking = TRUE)
      }
      d = dim(data)
      num_dim = length(d)
      dim1 = d[1]
      dim2 = ifelse(num_dim >= 2, d[2], 1)
      dim3 = ifelse(num_dim >= 3, d[3], 1)
      num_frames = ifelse(num_dim >= 4, d[4], 1)
      writeBin(as.integer(1), fh, size = 4, endian = "big")
      writeBin(as.integer(dim1), fh, size = 4, endian = "big")
      writeBin(as.integer(dim2), fh, size = 4, endian = "big")
      writeBin(as.integer(dim3), fh, size = 4, endian = "big")
      writeBin(as.integer(num_frames), fh, size = 4, endian = "big")
      if (num_dim >= 5) {
          stop(sprintf("The data must not have more than 4 dimensions, but it has %d.", 
              num_dim))
      }
      MRI_UCHAR = 0L
      MRI_INT = 1L
      MRI_FLOAT = 3L
      MRI_SHORT = 4L
      if (typeof(data) == "integer") {
          writeBin(as.integer(MRI_INT), fh, size = 4, endian = "big")
      }
      else if (typeof(data) == "double") {
          writeBin(as.integer(MRI_FLOAT), fh, size = 4, endian = "big")
      }
      else {
          stop(sprintf("Data type '%s' not supported. Try integer or double.", 
              typeof(data)))
      }
      dof = 0
      writeBin(as.integer(dof), fh, size = 4, endian = "big")
      header_size_total = 256
      writeBin(as.integer(ras_flag), fh, size = 2, endian = "big")
      if (ras_flag == 1) {
          MdcD = vox2ras_matrix[1:3, 1:3]
          delta = sqrt(colSums(MdcD^2))
          delta_tvec = rep(delta, 3)
          Mdc = as.vector(MdcD/delta_tvec)
          Pcrs_c = c(dim1/2, dim2/2, dim3/2, 1)
          Pxyz_c = vox2ras_matrix %*% Pcrs_c
          Pxyz_c = Pxyz_c[1:3]
          writeBin(delta, fh, size = 4, endian = "big")
          writeBin(Mdc, fh, size = 4, endian = "big")
          writeBin(Pxyz_c, fh, size = 4, endian = "big")
          used_space_RAS = (3 * 4 + 4 * 3 * 4)
      }
      else {
          used_space_RAS = 0
      }
      space_to_fill = header_size_total - 2 - used_space_RAS
      writeBin(as.integer(rep.int(0, space_to_fill)), fh, size = 1, 
          endian = "big")
      writeBin(as.vector(data), fh, size = 4, endian = "big")
      writeBin(mr_params, fh, size = 4, endian = "big")
      close(fh)
  }
  <bytecode: 0x558f7da24760>
  <environment: namespace:freesurferformats>
   --- function search by body ---
  Function write.fs.mgh in namespace freesurferformats has this body.
   ----------- END OF FAILURE REPORT -------------- 
  Fatal error: the condition has length > 1