tests/testthat/test-toJSON-matrix.R

test_that("Encoding a Matrix", {
  expect_equal(toJSON(matrix(1)), "[[1]]")
  expect_equal(toJSON(matrix(pi), digits = 5), "[[3.14159]]")
  expect_equal(toJSON(matrix(1:2)), "[[1],[2]]")
  expect_equal(toJSON(matrix(1:2, nrow = 1)), "[[1,2]]")
  expect_equal(toJSON(matrix(state.x77[1, 1, drop = FALSE])), "[[3615]]")
})

Try the jsonlite package in your browser

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

jsonlite documentation built on April 4, 2025, 5:24 a.m.