tests/testthat/test-toJSON-factor.R

context("toJSON Factor")

test_that("Encoding Factor Objects", {
  expect_that(fromJSON(toJSON(iris$Species)), is_identical_to(as.character(iris$Species)));
  expect_that(fromJSON(toJSON(iris$Species[1])), is_identical_to(as.character(iris$Species[1])));
  expect_that(fromJSON(toJSON(iris$Species, factor="integer")), equals(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 July 9, 2023, 6:11 p.m.