From ae7e4dcecbb311adb8ff4332a98a2277881b4ea1 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 10 Sep 2023 20:02:40 +1000 Subject: [PATCH] rename opts --- DESCRIPTION | 2 +- NAMESPACE | 8 ++-- NEWS.md | 7 +++- R/geojson.R | 12 +++--- R/json-opts.R | 18 ++++----- R/json.R | 10 ++--- README.Rmd | 25 ++++++------ README.md | 39 ++++++++----------- ...m_geojson_opts.Rd => opts_read_geojson.Rd} | 6 +-- man/{from_opts.Rd => opts_read_json.Rd} | 6 +-- ..._geojson_opts.Rd => opts_write_geojson.Rd} | 6 +-- man/{to_opts.Rd => opts_write_json.Rd} | 8 ++-- man/read_flag.Rd | 4 +- man/read_geojson_str.Rd | 2 +- man/read_json_conn.Rd | 4 +- man/read_json_file.Rd | 4 +- man/read_json_raw.Rd | 4 +- man/read_json_str.Rd | 4 +- man/read_ndjson_file.Rd | 4 +- man/validate_json_file.Rd | 4 +- man/write_flag.Rd | 4 +- man/write_geojson_str.Rd | 2 +- man/write_json_file.Rd | 4 +- man/write_json_str.Rd | 6 +-- man/write_ndjson_file.Rd | 4 +- tests/testthat/test-handling-specials.R | 32 +++++++-------- 26 files changed, 113 insertions(+), 116 deletions(-) rename man/{from_geojson_opts.Rd => opts_read_geojson.Rd} (92%) rename man/{from_opts.Rd => opts_read_json.Rd} (97%) rename man/{to_geojson_opts.Rd => opts_write_geojson.Rd} (76%) rename man/{to_opts.Rd => opts_write_json.Rd} (94%) diff --git a/DESCRIPTION b/DESCRIPTION index dd1dff5..2704580 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "mikefc@coolbutuseless.com"), person("Yao", "Yuan", role = "cph", email = "ibireme@gmail.com", diff --git a/NAMESPACE b/NAMESPACE index 2f15814..cd2b70b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/NEWS.md b/NEWS.md index 711e34b..8841089 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/geojson.R b/R/geojson.R index 87318f6..e72bc08 100644 --- a/R/geojson.R +++ b/R/geojson.R @@ -16,7 +16,7 @@ #' @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( @@ -24,7 +24,7 @@ from_geojson_opts <- function(type = c('sf', 'sfc'), type = match.arg(type), property_promotion = match.arg(property_promotion) ), - class = "from_geojson_opts" + class = "opts_read_geojson" ) } @@ -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" ) } @@ -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} #' @@ -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} #' diff --git a/R/json-opts.R b/R/json-opts.R index 614c6d7..256b168 100644 --- a/R/json-opts.R +++ b/R/json-opts.R @@ -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}{ @@ -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)) #' } #' #' @@ -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}{ @@ -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 @@ -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, @@ -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" ) } @@ -246,7 +246,7 @@ from_opts <- function( #' #' @examples #' \dontrun{ -#' write_json_str(iris, opts = to_opts(factor = 'integer')) +#' write_json_str(iris, opts = opts_write_json(factor = 'integer')) #' } #' #' @@ -254,7 +254,7 @@ from_opts <- function( #' @return Named list of options #' @export #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -to_opts <- function( +opts_write_json <- function( dataframe = c("rows", "columns"), factor = c("string", "integer"), auto_unbox = FALSE, @@ -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" ) } diff --git a/R/json.R b/R/json.R index 374fb96..15d4210 100644 --- a/R/json.R +++ b/R/json.R @@ -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 @@ -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 diff --git a/README.Rmd b/README.Rmd index f56f529..e48a3a3 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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 | | diff --git a/README.md b/README.md index a60e4c9..d96e890 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/man/from_geojson_opts.Rd b/man/opts_read_geojson.Rd similarity index 92% rename from man/from_geojson_opts.Rd rename to man/opts_read_geojson.Rd index 3087510..293bf1b 100644 --- a/man/from_geojson_opts.Rd +++ b/man/opts_read_geojson.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/geojson.R -\name{from_geojson_opts} -\alias{from_geojson_opts} +\name{opts_read_geojson} +\alias{opts_read_geojson} \title{Options for reading in GeoJSON} \usage{ -from_geojson_opts( +opts_read_geojson( type = c("sf", "sfc"), property_promotion = c("string", "list"), property_promotion_lgl_as_int = c("integer", "string") diff --git a/man/from_opts.Rd b/man/opts_read_json.Rd similarity index 97% rename from man/from_opts.Rd rename to man/opts_read_json.Rd index edc0515..422c9a9 100644 --- a/man/from_opts.Rd +++ b/man/opts_read_json.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/json-opts.R -\name{from_opts} -\alias{from_opts} +\name{opts_read_json} +\alias{opts_read_json} \title{Create named list of options for parsing R from JSON} \usage{ -from_opts( +opts_read_json( int64 = c("string", "bit64"), missing_list_elem = c("null", "na"), vectors_to_df = TRUE, diff --git a/man/to_geojson_opts.Rd b/man/opts_write_geojson.Rd similarity index 76% rename from man/to_geojson_opts.Rd rename to man/opts_write_geojson.Rd index 300a1f3..4185595 100644 --- a/man/to_geojson_opts.Rd +++ b/man/opts_write_geojson.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/geojson.R -\name{to_geojson_opts} -\alias{to_geojson_opts} +\name{opts_write_geojson} +\alias{opts_write_geojson} \title{Options for writing from \code{sf} object to \code{GeoJSON}} \usage{ -to_geojson_opts() +opts_write_geojson() } \value{ named list of options diff --git a/man/to_opts.Rd b/man/opts_write_json.Rd similarity index 94% rename from man/to_opts.Rd rename to man/opts_write_json.Rd index bfc08dd..3490653 100644 --- a/man/to_opts.Rd +++ b/man/opts_write_json.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/json-opts.R -\name{to_opts} -\alias{to_opts} +\name{opts_write_json} +\alias{opts_write_json} \title{Create named list of options for serializing R to JSON} \usage{ -to_opts( +opts_write_json( dataframe = c("rows", "columns"), factor = c("string", "integer"), auto_unbox = FALSE, @@ -55,7 +55,7 @@ Create named list of options for serializing R to JSON } \examples{ \dontrun{ -write_json_str(iris, opts = to_opts(factor = 'integer')) +write_json_str(iris, opts = opts_write_json(factor = 'integer')) } diff --git a/man/read_flag.Rd b/man/read_flag.Rd index 9980370..6dc9f88 100644 --- a/man/read_flag.Rd +++ b/man/read_flag.Rd @@ -18,7 +18,7 @@ code directly. This is an ADVANCED option and should be used with caution. Some of these settings overlap and conflict with code needed to handle the translation of JSON values to R. -\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}{ @@ -88,7 +88,7 @@ The flag will be overridden by "YYJSON_READ_NUMBER_AS_RAW" flag. } \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)) } diff --git a/man/read_geojson_str.Rd b/man/read_geojson_str.Rd index 87ce9d9..748110b 100644 --- a/man/read_geojson_str.Rd +++ b/man/read_geojson_str.Rd @@ -12,7 +12,7 @@ read_geojson_file(filename, opts = list(), ...) \arguments{ \item{str}{single character string containing GeoJSON} -\item{opts}{named list of options. Usually created with \code{from_geojson_opts()}. +\item{opts}{named list of options. Usually created with \code{opts_read_geojson()}. Default: empty \code{list()} to use the default options.} \item{...}{any extra named options override those in \code{opts}} diff --git a/man/read_json_conn.Rd b/man/read_json_conn.Rd index e9eb877..1ec836d 100644 --- a/man/read_json_conn.Rd +++ b/man/read_json_conn.Rd @@ -9,10 +9,10 @@ read_json_conn(conn, opts = list(), ...) \arguments{ \item{conn}{connection object. e.g. \code{url('https://jsonplaceholder.typicode.com/todos/1')}} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} } \value{ R object diff --git a/man/read_json_file.Rd b/man/read_json_file.Rd index 0994b1b..58c04a2 100644 --- a/man/read_json_file.Rd +++ b/man/read_json_file.Rd @@ -9,10 +9,10 @@ read_json_file(filename, opts = list(), ...) \arguments{ \item{filename}{full path to text file containing JSON.} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} } \value{ R object diff --git a/man/read_json_raw.Rd b/man/read_json_raw.Rd index 263b263..b7a4d07 100644 --- a/man/read_json_raw.Rd +++ b/man/read_json_raw.Rd @@ -9,10 +9,10 @@ read_json_raw(raw_vec, opts = list(), ...) \arguments{ \item{raw_vec}{raw vector} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} } \value{ R object diff --git a/man/read_json_str.Rd b/man/read_json_str.Rd index 6fa6ab3..0232506 100644 --- a/man/read_json_str.Rd +++ b/man/read_json_str.Rd @@ -9,10 +9,10 @@ read_json_str(str, opts = list(), ...) \arguments{ \item{str}{a single character string} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} } \value{ R object diff --git a/man/read_ndjson_file.Rd b/man/read_ndjson_file.Rd index 1051d3a..01273b7 100644 --- a/man/read_ndjson_file.Rd +++ b/man/read_ndjson_file.Rd @@ -26,10 +26,10 @@ read_ndjson_file( \item{nprobe}{Number of lines to read to determine types for data.frame columns. Default: 100. Only valid for \code{read_ndjson_file()}} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} } \value{ list or data.frame diff --git a/man/validate_json_file.Rd b/man/validate_json_file.Rd index 2855b1c..c3d292d 100644 --- a/man/validate_json_file.Rd +++ b/man/validate_json_file.Rd @@ -15,10 +15,10 @@ validate_json_str(str, verbose = FALSE, opts = list(), ...) \item{verbose}{logical. If the JSON is not valid, should a warning be shown giving details?} -\item{opts}{Named list of options for parsing. Usually created by \code{from_opts()}} +\item{opts}{Named list of options for parsing. Usually created by \code{opts_read_json()}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=from_opts]{from_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_read_json]{opts_read_json()}}} \item{str}{character string containing JSON} } diff --git a/man/write_flag.Rd b/man/write_flag.Rd index 19843c6..a756fdc 100644 --- a/man/write_flag.Rd +++ b/man/write_flag.Rd @@ -18,7 +18,7 @@ code directly. This is an ADVANCED option and should be used with caution. Some of these settings overlap and conflict with code needed to handle the translation of JSON values to R. -\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}{ @@ -50,7 +50,7 @@ This flag will override \code{YYJSON_WRITE_PRETTY} flag.} } \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)) } } diff --git a/man/write_geojson_str.Rd b/man/write_geojson_str.Rd index 87b7e3d..65834f6 100644 --- a/man/write_geojson_str.Rd +++ b/man/write_geojson_str.Rd @@ -12,7 +12,7 @@ write_geojson_file(x, filename, opts = list(), ...) \arguments{ \item{x}{\code{sf} object. Supports \code{sf} or \code{sfc}} -\item{opts}{named list of options. Usually created with \code{to_geojson_opts()}. +\item{opts}{named list of options. Usually created with \code{opts_write_geojson()}. Default: empty \code{list()} to use the default options.} \item{...}{any extra named options override those in \code{opts}} diff --git a/man/write_json_file.Rd b/man/write_json_file.Rd index b0f64c0..5885c87 100644 --- a/man/write_json_file.Rd +++ b/man/write_json_file.Rd @@ -11,10 +11,10 @@ write_json_file(x, filename, opts = list(), ...) \item{filename}{filename} -\item{opts}{Named list of serialization options. Usually created by \code{\link[=to_opts]{to_opts()}}} +\item{opts}{Named list of serialization options. Usually created by \code{\link[=opts_write_json]{opts_write_json()}}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=to_opts]{to_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_write_json]{opts_write_json()}}} } \description{ Convert R object to JSON file diff --git a/man/write_json_str.Rd b/man/write_json_str.Rd index 1fec960..48eb0f2 100644 --- a/man/write_json_str.Rd +++ b/man/write_json_str.Rd @@ -9,10 +9,10 @@ write_json_str(x, opts = list(), ...) \arguments{ \item{x}{the object to be encoded} -\item{opts}{Named list of serialization options. Usually created by \code{\link[=to_opts]{to_opts()}}} +\item{opts}{Named list of serialization options. Usually created by \code{\link[=opts_write_json]{opts_write_json()}}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=to_opts]{to_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_write_json]{opts_write_json()}}} } \value{ Character string @@ -23,7 +23,7 @@ Convert R object to JSON 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)) } } diff --git a/man/write_ndjson_file.Rd b/man/write_ndjson_file.Rd index 1bb93bd..22805e4 100644 --- a/man/write_ndjson_file.Rd +++ b/man/write_ndjson_file.Rd @@ -14,10 +14,10 @@ write_ndjson_str(x, opts = list(), ...) \item{filename}{filename} -\item{opts}{Named list of serialization options. Usually created by \code{\link[=to_opts]{to_opts()}}} +\item{opts}{Named list of serialization options. Usually created by \code{\link[=opts_write_json]{opts_write_json()}}} \item{...}{Other named options can be used to override any options in \code{opts}. -The valid named options are identical to arguments to \code{\link[=to_opts]{to_opts()}}} +The valid named options are identical to arguments to \code{\link[=opts_write_json]{opts_write_json()}}} } \description{ Write list or data.frame object to ndjson diff --git a/tests/testthat/test-handling-specials.R b/tests/testthat/test-handling-specials.R index 9b36f11..34e9a1a 100644 --- a/tests/testthat/test-handling-specials.R +++ b/tests/testthat/test-handling-specials.R @@ -10,12 +10,12 @@ test_that("to_json handling specials works", { ) expect_identical( - write_json_str(c(TRUE, NA), opts = to_opts(num_specials = 'string')), + write_json_str(c(TRUE, NA), opts = opts_write_json(num_specials = 'string')), '[true,"NA"]' ) expect_identical( - write_json_str(c(TRUE, NA), opts = to_opts(num_specials = 'null')), + write_json_str(c(TRUE, NA), opts = opts_write_json(num_specials = 'null')), '[true,null]' ) @@ -29,12 +29,12 @@ test_that("to_json handling specials works", { ) expect_identical( - write_json_str(c(0L, NA_integer_), opts = to_opts(num_specials = 'string')), + write_json_str(c(0L, NA_integer_), opts = opts_write_json(num_specials = 'string')), '[0,"NA"]' ) expect_identical( - write_json_str(c(0L, NA_integer_), opts = to_opts(num_specials = 'null')), + write_json_str(c(0L, NA_integer_), opts = opts_write_json(num_specials = 'null')), '[0,null]' ) @@ -48,12 +48,12 @@ test_that("to_json handling specials works", { ) expect_identical( - write_json_str(c("a", NA_character_), opts = to_opts(str_specials = 'string')), + write_json_str(c("a", NA_character_), opts = opts_write_json(str_specials = 'string')), '["a","NA"]' ) expect_identical( - write_json_str(c("a", NA_character_), opts = to_opts(str_specials = 'null')), + write_json_str(c("a", NA_character_), opts = opts_write_json(str_specials = 'null')), '["a",null]' ) @@ -67,12 +67,12 @@ test_that("to_json handling specials works", { ) expect_identical( - write_json_str(c(0, NA_real_, Inf, -Inf, NaN), opts = to_opts(num_specials = 'string')), + write_json_str(c(0, NA_real_, Inf, -Inf, NaN), opts = opts_write_json(num_specials = 'string')), '[0.0,"NA","Inf","-Inf","NaN"]' ) expect_identical( - write_json_str(c(0, NA_real_, Inf, -Inf, NaN), opts = to_opts(num_specials = 'null')), + write_json_str(c(0, NA_real_, Inf, -Inf, NaN), opts = opts_write_json(num_specials = 'null')), '[0.0,null,null,null,null]' ) }) @@ -89,12 +89,12 @@ test_that("from_json handling specials works", { ) expect_identical( - read_json_str('[true,"NA"]', opts = from_opts(num_specials = "special")), + read_json_str('[true,"NA"]', opts = opts_read_json(num_specials = "special")), c(TRUE, NA) ) expect_identical( - read_json_str('[true,"NA"]', opts = from_opts(num_specials = "string")), + read_json_str('[true,"NA"]', opts = opts_read_json(num_specials = "string")), list(TRUE, "NA") ) @@ -107,12 +107,12 @@ test_that("from_json handling specials works", { ) expect_identical( - read_json_str('[0, "NA"]', opts = from_opts(num_specials = "special")), + read_json_str('[0, "NA"]', opts = opts_read_json(num_specials = "special")), c(0L, NA_integer_) ) expect_identical( - read_json_str('[0, "NA"]', opts = from_opts(num_specials = "string")), + read_json_str('[0, "NA"]', opts = opts_read_json(num_specials = "string")), list(0L, "NA") ) @@ -126,12 +126,12 @@ test_that("from_json handling specials works", { ) expect_identical( - read_json_str('[0.0, "NA", "Inf", "-Inf", "NaN"]', opts = from_opts(num_specials = "special")), + read_json_str('[0.0, "NA", "Inf", "-Inf", "NaN"]', opts = opts_read_json(num_specials = "special")), c(0, NA_real_, Inf, -Inf, NaN) ) expect_identical( - read_json_str('[0.0, "NA", "Inf", "-Inf", "NaN"]', opts = from_opts(num_specials = "string")), + read_json_str('[0.0, "NA", "Inf", "-Inf", "NaN"]', opts = opts_read_json(num_specials = "string")), list(0, "NA", "Inf", "-Inf", "NaN") ) @@ -144,12 +144,12 @@ test_that("from_json handling specials works", { ) expect_identical( - read_json_str('["a", "NA"]', opts = from_opts(str_specials = "string")), + read_json_str('["a", "NA"]', opts = opts_read_json(str_specials = "string")), c("a", "NA") ) expect_identical( - read_json_str('["a", "NA"]', opts = from_opts(str_specials = "special")), + read_json_str('["a", "NA"]', opts = opts_read_json(str_specials = "special")), c("a", NA_character_) )