jsonlite icon indicating copy to clipboard operation
jsonlite copied to clipboard

Respect scipen option or add an explicit scipen option to `toJSON`

Open vspinu opened this issue 4 years ago • 1 comments

There are use cases when the difference between 0.0001 and 1e-5 is crucial.

My use case is to print two jsons and run diff tools on the output to detect any regularities between expected and produced jsons in tests.

The problem is that on some inputs scipen is not applied and I am getting spurious failures like:

-        "pred.applied": 1e-05,
+        "pred.applied": 0.00001,

vspinu avatar Aug 05 '21 10:08 vspinu

Also it seems like digit argument is not quite respected:

> (toJSON(0.0001, pretty = TRUE, digits = 3))
[0] 
> (toJSON(0.00001, pretty = TRUE, digits = 3))
[1e-05] 
> 

vspinu avatar Aug 05 '21 10:08 vspinu