tests/testthat/test-opt-digits-promote.R

test_that("option 'digits_promote' works", {

  j <- '[1.234567890123456,"hello"]'
  x <- read_json_str(j)
  expect_true(is.list(x))
  expect_equal(x[[1]], 1.234567890123456)
  
  
  x <- read_json_str(j, opts = opts_read_json(promote_num_to_string = TRUE))
  x
  expect_true(is.atomic(x))
  expect_equal(x[[1]], "1.234568")
  
  
  x <- read_json_str(j, opts = opts_read_json(promote_num_to_string = TRUE,
                                              digits_promote = 15))
  x
  expect_true(is.atomic(x))
  expect_equal(x[[1]], "1.234567890123456")

  
})

Try the yyjsonr package in your browser

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

yyjsonr documentation built on June 8, 2025, 10:47 a.m.