-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize R implementation / documentation
- Loading branch information
Showing
7 changed files
with
164 additions
and
126 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
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,59 @@ | ||
#' @rdname as_r | ||
#' | ||
#' @title Parse JSON to R | ||
#' | ||
#' @description `as_r()` transforms a JSON string to an *R* object. | ||
#' | ||
#' @inheritParams jsonpath | ||
#' | ||
#' @details | ||
#' | ||
#' The `as = "R"` argument to `jsonpath()`, `jmespath()` and | ||
#' `jsonpivot()`, and the `as_r()` function transform a JSON string | ||
#' representation to an *R* object. Main rules are: | ||
#' | ||
#' - JSON arrays of a single type (boolean, integer, double, string) | ||
#' are transformed to *R* vectors of the same length and | ||
#' corresponding type. A JSON scalar and a JSON vector of length 1 | ||
#' are represented in the same way in *R*. | ||
#' | ||
#' - If a JSON 64-bit integer array contains a value larger than *R*'s | ||
#' 32-bit integer representation, the array is transformed to an *R* | ||
#' numeric vector. NOTE that this results in loss of precision for | ||
#' 64-bit integer values greater than `2^53`. | ||
#' | ||
#' - JSON arrays mixing integer and double values are transformed to | ||
#' *R* numeric vectors. | ||
#' | ||
#' - JSON objects are transformed to *R* named lists. | ||
#' | ||
#' The vignette reiterates this information and provides additional | ||
#' details. | ||
#' | ||
#' @examples | ||
#' ## as_r() | ||
#' as_r('[1, 2, 3]') # JSON integer array -> R integer vector | ||
#' as_r('[1, 2.0, 3]') # JSON intger and double array -> R numeric vector | ||
#' as_r('[1, 2.0, "3"]') # JSON mixed array -> R list | ||
#' as_r('[1, 2147483648]') # JSON integer > R integer max -> R numeric vector | ||
#' | ||
#' json <- '{"b": 1, "a": ["c", "d"], "e": true, "f": [true], "g": {}}' | ||
#' as_r(json) |> str() # parsing complex objects | ||
#' identical( # JSON scalar and length 1 array identical in R | ||
#' as_r('{"a": 1}'), as_r('{"a": [1]}') | ||
#' ) | ||
#' | ||
#' @return `as_r()` returns an *R* object. | ||
#' | ||
#' @export | ||
as_r <- | ||
function(data, object_names = "asis", ...) | ||
{ | ||
stopifnot( | ||
.is_scalar_character(data), | ||
.is_scalar_character(object_names) | ||
) | ||
|
||
data <- .as_json_string(data, ...) | ||
cpp_as_r(data, object_names) | ||
} |
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,18 @@ | ||
#' @useDynLib rjsoncons, .registration = TRUE | ||
NULL | ||
|
||
#' @rdname version | ||
#' | ||
#' @title Version of jsoncons C++ library | ||
#' | ||
#' @description `version()` reports the version of the C++ jsoncons | ||
#' library in use. | ||
#' | ||
#' @return `version()` returns a character(1) major.minor.patch | ||
#' version string . | ||
#' | ||
#' @examples | ||
#' version() | ||
#' | ||
#' @export | ||
version <- cpp_version |
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.