-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'digits' argument when writing JSON
- Loading branch information
1 parent
7bafff5
commit dfd5036
Showing
14 changed files
with
190 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: yyjsonr | ||
Type: Package | ||
Title: Fast JSON, GeoJSON and NDJSON Parsing and Serialisation | ||
Version: 0.1.10 | ||
Version: 0.1.11 | ||
Authors@R: c( | ||
person("Mike", "FC", role = c("aut", "cre"), email = "[email protected]"), | ||
person("Yao", "Yuan", role = "cph", email = "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
test_that("digits argument works", { | ||
|
||
robj <- c(1.51, 2, 3.141592654) | ||
|
||
|
||
expect_equal( | ||
write_json_str(robj, digits = -1), | ||
"[1.51,2.0,3.141592654]" | ||
) | ||
|
||
expect_equal( | ||
write_json_str(robj, digits = 0), | ||
"[2,2,3]" | ||
) | ||
|
||
expect_equal( | ||
write_json_str(robj, digits = 1), | ||
"[1.5,2.0,3.1]" | ||
) | ||
|
||
expect_equal( | ||
write_json_str(robj, digits = 2), | ||
"[1.51,2.0,3.14]" | ||
) | ||
|
||
|
||
|
||
expect_equal( | ||
write_json_str(pi, digits = 0), | ||
"[3]" | ||
) | ||
|
||
expect_equal( | ||
write_json_str(pi, digits = 1), | ||
"[3.1]" | ||
) | ||
|
||
expect_equal( | ||
write_json_str(pi, digits = 4), | ||
"[3.1416]" | ||
) | ||
|
||
|
||
expect_equal( | ||
write_json_str(pi, digits = 4, auto_unbox = TRUE), | ||
"3.1416" | ||
) | ||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
js <- r"( | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
-80.870885, | ||
35.215151 | ||
] | ||
}, | ||
"properties": { | ||
"value": 1.0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
-80.837753, | ||
35.249801 | ||
] | ||
}, | ||
"properties": { | ||
"value": "a" | ||
} | ||
} | ||
] | ||
} | ||
)" | ||
|
||
|
||
test_that("geojson digits works", { | ||
|
||
x <- read_geojson_str(js) | ||
|
||
js2 <- write_geojson_str(x, digits = 0) | ||
|
||
x2 <- read_geojson_str(js2) | ||
|
||
expect_equal(unclass(x2$geometry[[1]]), c(-81, 35)) | ||
expect_equal(unclass(x2$geometry[[2]]), c(-81, 35)) | ||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters