Skip to content

Commit

Permalink
rename opts
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Sep 10, 2023
1 parent 6ef737e commit ae7e4dc
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 116 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
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.6
Version: 0.1.7
Authors@R: c(
person("Mike", "FC", role = c("aut", "cre"), email = "[email protected]"),
person("Yao", "Yuan", role = "cph", email = "[email protected]",
Expand Down
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(from_geojson_opts)
export(from_opts)
export(opts_read_geojson)
export(opts_read_json)
export(opts_write_geojson)
export(opts_write_json)
export(read_flag)
export(read_geojson_file)
export(read_geojson_str)
Expand All @@ -10,8 +12,6 @@ export(read_json_file)
export(read_json_raw)
export(read_json_str)
export(read_ndjson_file)
export(to_geojson_opts)
export(to_opts)
export(validate_json_file)
export(validate_json_str)
export(write_flag)
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@


# yyjsonr 0.1.7 2023-09-10

* Unifed naming scheme

# yyjsonr 0.1.6 2023-09-04

* FEATURE: Added `promote_num_to_string` in `from_opts()` to enable
* FEATURE: Added `promote_num_to_string` in `opts_read_json()` to enable
forced promotion of numerics to string
* BUGFIX: fixes for handling of geometry collection when reading and writing.
* TESTING: More tests included for output to geojson
Expand Down
12 changes: 6 additions & 6 deletions R/geojson.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#' @return named list
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from_geojson_opts <- function(type = c('sf', 'sfc'),
opts_read_geojson <- function(type = c('sf', 'sfc'),
property_promotion = c('string', 'list'),
property_promotion_lgl_as_int = c('integer', 'string')) {
structure(
list(
type = match.arg(type),
property_promotion = match.arg(property_promotion)
),
class = "from_geojson_opts"
class = "opts_read_geojson"
)
}

Expand All @@ -36,12 +36,12 @@ from_geojson_opts <- function(type = c('sf', 'sfc'),
#' @return named list of options
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
to_geojson_opts <- function() {
opts_write_geojson <- function() {
structure(
list(

),
class = "to_geojson_opts"
class = "opts_write_geojson"
)
}

Expand All @@ -51,7 +51,7 @@ to_geojson_opts <- function() {
#'
#' @param filename filename
#' @param str single character string containing GeoJSON
#' @param opts named list of options. Usually created with \code{from_geojson_opts()}.
#' @param opts named list of options. Usually created with \code{opts_read_geojson()}.
#' Default: empty \code{list()} to use the default options.
#' @param ... any extra named options override those in \code{opts}
#'
Expand Down Expand Up @@ -90,7 +90,7 @@ read_geojson_file <- function(filename, opts = list(), ...) {
#'
#' @param x \code{sf} object. Supports \code{sf} or \code{sfc}
#' @param filename filename
#' @param opts named list of options. Usually created with \code{to_geojson_opts()}.
#' @param opts named list of options. Usually created with \code{opts_write_geojson()}.
#' Default: empty \code{list()} to use the default options.
#' @param ... any extra named options override those in \code{opts}
#'
Expand Down
18 changes: 9 additions & 9 deletions R/json-opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' the translation of JSON values to R.
#'
#" Pass multiple options with
#' \code{from_opts(yyjson_read_flag = c(read_flag$x, read_flag$y, ...))}
#' \code{opts_read_json(yyjson_read_flag = c(read_flag$x, read_flag$y, ...))}
#'
#' \describe{
#' \item{YYJSON_READ_NOFLAG}{
Expand Down Expand Up @@ -79,7 +79,7 @@
#'
#' @examples
#' \dontrun{
#' read_json_str(str, opts = from_opts(yyjson_read_flag = read_flag$YYJSON_READ_NUMBER_AS_RAW))
#' read_json_str(str, opts = opts_read_json(yyjson_read_flag = read_flag$YYJSON_READ_NUMBER_AS_RAW))
#' }
#'
#'
Expand Down Expand Up @@ -108,7 +108,7 @@ read_flag <- list(
#' the translation of JSON values to R.
#'
#" Pass multiple options with
#' \code{to_opts(yyjson_write_flag = c(write_flag$x, write_flag$y, ...))}
#' \code{opts_write_json(yyjson_write_flag = c(write_flag$x, write_flag$y, ...))}
#'
#' \describe{
#' \item{YYJSON_WRITE_NOFLAG}{
Expand Down Expand Up @@ -141,7 +141,7 @@ read_flag <- list(
#'
#' @examples
#' \dontrun{
#' write_json_str(str, opts = to_opts(yyjson_write_flag = write_flag$YYJSON_WRITE_ESCAPE_SLASHES))
#' write_json_str(str, opts = opts_write_json(yyjson_write_flag = write_flag$YYJSON_WRITE_ESCAPE_SLASHES))
#' }
#'
#' @export
Expand Down Expand Up @@ -193,7 +193,7 @@ write_flag <- list(
#' @return Named list of options
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from_opts <- function(
opts_read_json <- function(
int64 = c('string', 'bit64'),
missing_list_elem = c('null', 'na'),
vectors_to_df = TRUE,
Expand All @@ -212,7 +212,7 @@ from_opts <- function(
num_specials = match.arg(num_specials),
yyjson_read_flag = as.integer(yyjson_read_flag)
),
class = "from_opts"
class = "opts_read_json"
)
}

Expand Down Expand Up @@ -246,15 +246,15 @@ from_opts <- function(
#'
#' @examples
#' \dontrun{
#' write_json_str(iris, opts = to_opts(factor = 'integer'))
#' write_json_str(iris, opts = opts_write_json(factor = 'integer'))
#' }
#'
#'
#' @seealso [write_flag()]
#' @return Named list of options
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
to_opts <- function(
opts_write_json <- function(
dataframe = c("rows", "columns"),
factor = c("string", "integer"),
auto_unbox = FALSE,
Expand All @@ -275,6 +275,6 @@ to_opts <- function(
num_specials = match.arg(num_specials),
yyjson_write_flag = as.integer(yyjson_write_flag)
),
class = "to_opts"
class = "opts_write_json"
)
}
10 changes: 5 additions & 5 deletions R/json.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#' Convert JSON in a character string to R
#'
#' @param str a single character string
#' @param opts Named list of options for parsing. Usually created by \code{from_opts()}
#' @param opts Named list of options for parsing. Usually created by \code{opts_read_json()}
#' @param ... Other named options can be used to override any options in \code{opts}.
#' The valid named options are identical to arguments to [from_opts()]
#' The valid named options are identical to arguments to [opts_read_json()]
#'
#'
#' @examples
Expand Down Expand Up @@ -110,16 +110,16 @@ read_json_conn <- function(conn, opts = list(), ...) {
#' Convert R object to JSON string
#'
#' @param x the object to be encoded
#' @param opts Named list of serialization options. Usually created by [to_opts()]
#' @param opts Named list of serialization options. Usually created by [opts_write_json()]
#' @param ... Other named options can be used to override any options in \code{opts}.
#' The valid named options are identical to arguments to [to_opts()]
#' The valid named options are identical to arguments to [opts_write_json()]
#'
#' @return Character string
#'
#' @examples
#' \dontrun{
#' write_json_str(iris, pretty = TRUE)
#' write_json_str(iris, opts = to_opts(auto_unbox = FALSE))
#' write_json_str(iris, opts = opts_write_json(auto_unbox = FALSE))
#' }
#'
#' @family JSON Serializer
Expand Down
25 changes: 11 additions & 14 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,21 @@ library (version `YYJSON_VERSION_HEX = 0x000700`).

### What's in the box

* Read/Write JSON as R objects
* `read_json_str()`, `read_json_file()`, `read_json_conn()`, `read_json_raw()`
* `write_json_str()`, `write_json_file()`
* Validate JSON
* `validate_json_str()`, `validate_json_file()`
* Read/Write GeoJSON to/from `{sf}` objects
* `read_geojson_str()`, `read_geojson_file()`
* `write_geojson_str()`, `write_geojson_file()`
* Read/Write NDJSON
* `read_ndjson_file()`, `read_ndjson_file()`
* `write_ndjson_file()`, `write_ndjson_str()`
* Construct configuration options for reading/writing JSON
* `to_opts()`, `from_opts()`
| | | string | file | raw | conn | options |
|---------|----------|---------------------|----------------------|-----------------|------------------|----------------------|
| json | read | read_json_str() | read_json_file() | read_json_raw() | read_json_conn() | opts_read_json() |
| | write | write_json_str() | write_json_file() | | | opts_write_json() |
| | validate | validate_json_str() | validate_json_file() | | | |
| geojson | read | read_geojson_str() | read_geojson_file() | | | opts_read_geojson() |
| | write | write_geojson_str() | write_geojson_file() | | | opts_write_geojson() |
| ndjson | read | | read_ndjson_file() | | | |
| | write | write_ndjson_str() | write_ndjson_file() | | | |



### Comparison to other JSON packages

| | R to JSON | JSON to R | ndjson read | ndjson write | geojson to/from `{sf}`|
| | Write JSON| Read JSON | READ ndjson | Write ndjson | R/W geojson `{sf}`|
|--------------|-----------|-----------|-------------|--------------|-------------------|
| yyjsonr | Fast! | Fast! | Fast! | Fast! | Fast! |
| jsonlite | Yes | Yes | Yes | Yes | |
Expand Down
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,26 @@ more details.

### What’s in the box

- Read/Write JSON as R objects
- `read_json_str()`, `read_json_file()`, `read_json_conn()`,
`read_json_raw()`
- `write_json_str()`, `write_json_file()`
- Validate JSON
- `validate_json_str()`, `validate_json_file()`
- Read/Write GeoJSON to/from `{sf}` objects
- `read_geojson_str()`, `read_geojson_file()`
- `write_geojson_str()`, `write_geojson_file()`
- Read/Write NDJSON
- `read_ndjson_file()`, `read_ndjson_file()`
- `write_ndjson_file()`, `write_ndjson_str()`
- Construct configuration options for reading/writing JSON
- `to_opts()`, `from_opts()`
| | | string | file | raw | conn | options |
|---------|----------|---------------------|----------------------|-----------------|------------------|----------------------|
| json | read | read_json_str() | read_json_file() | read_json_raw() | read_json_conn() | opts_read_json() |
| | write | write_json_str() | write_json_file() | | | opts_write_json() |
| | validate | validate_json_str() | validate_json_file() | | | |
| geojson | read | read_geojson_str() | read_geojson_file() | | | opts_read_geojson() |
| | write | write_geojson_str() | write_geojson_file() | | | opts_write_geojson() |
| ndjson | read | | read_ndjson_file() | | | |
| | write | write_ndjson_str() | write_ndjson_file() | | | |

### Comparison to other JSON packages

| | R to JSON | JSON to R | ndjson read | ndjson write | geojson to/from `{sf}` |
|--------------|-----------|-----------|-------------|--------------|------------------------|
| yyjsonr | Fast! | Fast! | Fast! | Fast! | Fast! |
| jsonlite | Yes | Yes | Yes | Yes | |
| RcppSimdJson | | Fast! | | | |
| jsonify | Yes | Yes | Yes | Yes | |
| ndjson | | | Yes | Yes | |
| geojsonsf | | | | | Yes |
| | Write JSON | Read JSON | READ ndjson | Write ndjson | R/W geojson `{sf}` |
|--------------|------------|-----------|-------------|--------------|--------------------|
| yyjsonr | Fast! | Fast! | Fast! | Fast! | Fast! |
| jsonlite | Yes | Yes | Yes | Yes | |
| RcppSimdJson | | Fast! | | | |
| jsonify | Yes | Yes | Yes | Yes | |
| ndjson | | | Yes | Yes | |
| geojsonsf | | | | | Yes |

<img src="man/figures/benchmark-summary.png">

Expand Down
6 changes: 3 additions & 3 deletions man/from_geojson_opts.Rd → man/opts_read_geojson.Rd

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

6 changes: 3 additions & 3 deletions man/from_opts.Rd → man/opts_read_json.Rd

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

6 changes: 3 additions & 3 deletions man/to_geojson_opts.Rd → man/opts_write_geojson.Rd

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

8 changes: 4 additions & 4 deletions man/to_opts.Rd → man/opts_write_json.Rd

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

4 changes: 2 additions & 2 deletions man/read_flag.Rd

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

2 changes: 1 addition & 1 deletion man/read_geojson_str.Rd

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

4 changes: 2 additions & 2 deletions man/read_json_conn.Rd

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

Loading

0 comments on commit ae7e4dc

Please sign in to comment.