tests/testthat/test-toJSON-factor.R

test_that("Encoding Factor Objects", {
  expect_identical(fromJSON(toJSON(iris$Species)), as.character(iris$Species))
  expect_identical(fromJSON(toJSON(iris$Species[1])), as.character(iris$Species[1]))
  expect_equal(fromJSON(toJSON(iris$Species, factor = "integer")), structure(unclass(iris$Species), levels = NULL))
})

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.