Skip to content

Commit

Permalink
MINOR: [R][Docs] Add note about conversion from JSON types to Arrow t…
Browse files Browse the repository at this point in the history
…ypes (apache#13871)

Add note about conversion from JSON types to Arrow types.
These documents were copied from `docs/source/python/json.rst` with modifications.

Also, show the data frame in the example to make it easier to understand how the conversion is performed.

Authored-by: SHIMA Tatsuya <[email protected]>
Signed-off-by: Neal Richardson <[email protected]>
  • Loading branch information
eitsupi authored Oct 13, 2022
1 parent a47cd52 commit 66e8ba5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 14 additions & 2 deletions r/R/json.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@
#' data frame or Arrow Table.
#'
#' If passed a path, will detect and handle compression from the file extension
#' (e.g. `.json.gz`). Accepts explicit or implicit nulls.
#' (e.g. `.json.gz`).
#'
#' If `schema` is not provided, Arrow data types are inferred from the data:
#' - JSON null values convert to the [null()] type, but can fall back to any other type.
#' - JSON booleans convert to [boolean()].
#' - JSON numbers convert to [int64()], falling back to [float64()] if a non-integer is encountered.
#' - JSON strings of the kind "YYYY-MM-DD" and "YYYY-MM-DD hh:mm:ss" convert to [`timestamp(unit = "s")`][timestamp()],
#' falling back to [utf8()] if a conversion error occurs.
#' - JSON arrays convert to a [list_of()] type, and inference proceeds recursively on the JSON arrays' values.
#' - Nested JSON objects convert to a [struct()] type, and inference proceeds recursively on the JSON objects' values.
#'
#' When `as_data_frame = FALSE`, Arrow types are further converted to R types.
#' See `vignette("arrow", package = "arrow")` for details.
#'
#' @inheritParams read_delim_arrow
#' @param schema [Schema] that describes the table.
Expand All @@ -37,7 +49,7 @@
#' { "hello": 3.25, "world": null }
#' { "hello": 0.0, "world": true, "yo": null }
#' ', tf, useBytes = TRUE)
#' df <- read_json_arrow(tf)
#' read_json_arrow(tf)
read_json_arrow <- function(file,
col_select = NULL,
as_data_frame = TRUE,
Expand Down
18 changes: 16 additions & 2 deletions r/man/read_json_arrow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 66e8ba5

Please sign in to comment.