From ef19929e85aef4180a8006b37bef2cf4736fc1e8 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 29 Oct 2023 11:38:00 +1000 Subject: [PATCH] Doc fixes [no ci] --- R/geojson.R | 4 ++-- R/json-opts.R | 2 +- R/ndjson.R | 8 ++++---- README.Rmd | 8 +------- man/benchmark/benchmarks.Rmd | 25 +++++++++++++++++++++++++ man/opts_read_geojson.Rd | 2 +- man/opts_read_json.Rd | 2 +- man/read_ndjson_file.Rd | 6 +++--- man/write_geojson_str.Rd | 4 ++-- man/write_ndjson_file.Rd | 4 ++-- 10 files changed, 42 insertions(+), 23 deletions(-) diff --git a/R/geojson.R b/R/geojson.R index cbbd247..cda0647 100644 --- a/R/geojson.R +++ b/R/geojson.R @@ -10,7 +10,7 @@ #' Default: 'string' will behave like 'geojsonsf' #' @param type 'sf' or 'sfc' #' @param property_promotion_lgl_as_int when promoting properties into a string, -#' should logical values beccome strings e.g. "TRUE" or integers +#' should logical values become strings e.g. "TRUE" or integers #' e.g. "1". Default: "integer" in order to match `geojsonsf` packages #' #' @return named list @@ -86,7 +86,7 @@ read_geojson_file <- function(filename, opts = list(), ...) { } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#' Write SF to geojson string +#' Write SF to GeoJSON string #' #' @param x \code{sf} object. Supports \code{sf} or \code{sfc} #' @param filename filename diff --git a/R/json-opts.R b/R/json-opts.R index f59dc98..24eb0ce 100644 --- a/R/json-opts.R +++ b/R/json-opts.R @@ -191,7 +191,7 @@ write_flag <- list( #' means to keep numerics as numeric value and promote the \emph{container} to #' be a \code{list} rather than an atomic vector when types are mixed. If \code{TRUE} #' then array of mixed string/numeric types will be promoted to all -#' string values and returned as an atonic character vector. Set this to \code{TRUE} +#' string values and returned as an atomic character vector. Set this to \code{TRUE} #' if you want to emulate the behaviour of \code{jsonlite::fromJSON()} #' @param length1_array_asis logical. Should JSON arrays with length = 1 be #' marked with class \code{AsIs}. Default: FALSE diff --git a/R/ndjson.R b/R/ndjson.R index ac87123..d50457c 100644 --- a/R/ndjson.R +++ b/R/ndjson.R @@ -1,12 +1,12 @@ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#' Parse an ndjson file to a data.frame or list +#' Parse an NDJSON file to a data.frame or list #' -#' If reading as data.frame, each row of ndjson becomes a row in the data.frame. +#' If reading as data.frame, each row of NDJSON becomes a row in the data.frame. #' If reading as a list, then each row becomes an element in the list. #' -#' If parsing ndjson to a data.frame it is usually better if the json objects +#' If parsing NDJSON to a data.frame it is usually better if the json objects #' are consistent from line-to-line. Type inference for the data.frame is done #' during initialisation by reading through \code{nprobe} lines. Warning: if #' there is a type-mismatch further into the file than it is probed, then you @@ -59,7 +59,7 @@ read_ndjson_file <- function(filename, type = c('df', 'list'), nread = -1, nskip #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#' Write list or data.frame object to ndjson +#' Write list or data.frame object to NDJSON #' #' @inherit write_json_file #' @param x data.frame or list diff --git a/README.Rmd b/README.Rmd index e48a3a3..4b3d057 100644 --- a/README.Rmd +++ b/README.Rmd @@ -128,12 +128,6 @@ read_json_str(str) Parsing differences compared to `{jsonlite}` ============================================================================= -No 'digits' argument ------------------------------------------------------------------------------ - -Numeric conversion is handled within the `yyjson` C library and is not -configuraable. - 3-d arrays are parsed as multiple 2-d matrices and combined ----------------------------------------------------------------------------- @@ -146,7 +140,7 @@ consistent within each package, but not cross-compatible between them i.e. you cannot serialize an array in `{yyjsonr}` and re-create it exactly using `{jsonlite}`. -The matrix handling in `{yyjsonr}` is compatible with the expectationf os GeoJSON +The matrix handling in `{yyjsonr}` is compatible with the expectations of GeoJSON coordinate handling. ```{r} diff --git a/man/benchmark/benchmarks.Rmd b/man/benchmark/benchmarks.Rmd index 2ec91a0..b74143e 100644 --- a/man/benchmark/benchmarks.Rmd +++ b/man/benchmark/benchmarks.Rmd @@ -208,7 +208,9 @@ res06 <- bench::mark( ndjson = ndjson::stream_in(ndjson_filename), jsonlite = jsonlite::stream_in(file(ndjson_filename), verbose = FALSE), jsonify = jsonify::from_ndjson(ndjson_filename), + # arrow = arrow::read_json_arrow(ndjson_filename), yyjsonr = yyjsonr::read_ndjson_file (ndjson_filename), + # relative = TRUE, check = FALSE ) ``` @@ -220,6 +222,29 @@ plot(res06) + theme_bw() + theme(legend.position = 'none') ``` +```{r echo=FALSE, eval=FALSE} +library(dplyr) +plot_df <- res06 %>% + mutate(package = as.character(expression)) %>% + rename(speed = `itr/sec`) + +ggplot(plot_df) + + geom_col(aes(package, speed, fill = package), + position = position_dodge2(preserve = "single")) + + theme_bw(20) + + theme(legend.position = 'none') + + scale_fill_manual(values = c(rep(grey(0.5), 4), 'dodgerblue3')) + + geom_hline(yintercept = 1, color = 'red', alpha = 0.5, linetype = 2) + + labs( + x = NULL, + y = "Factor speed increase over {jsonlite}", + title = "Reading NDJSON. Speed-up compared to {jsonlite}", + subtitle = "Red line indicates reference implementation {jsonlite}" + ) +``` + + + To NDJSON File ------------------------------------------------------------------------------- diff --git a/man/opts_read_geojson.Rd b/man/opts_read_geojson.Rd index 293bf1b..6fc476b 100644 --- a/man/opts_read_geojson.Rd +++ b/man/opts_read_geojson.Rd @@ -20,7 +20,7 @@ to a 'string', or contained as different types in a 'list'. Default: 'string' will behave like 'geojsonsf'} \item{property_promotion_lgl_as_int}{when promoting properties into a string, -should logical values beccome strings e.g. "TRUE" or integers +should logical values become strings e.g. "TRUE" or integers e.g. "1". Default: "integer" in order to match \code{geojsonsf} packages} } \value{ diff --git a/man/opts_read_json.Rd b/man/opts_read_json.Rd index 9c50930..73ae91c 100644 --- a/man/opts_read_json.Rd +++ b/man/opts_read_json.Rd @@ -50,7 +50,7 @@ when they occur within an array with other string values? Default: FALSE means to keep numerics as numeric value and promote the \emph{container} to be a \code{list} rather than an atomic vector when types are mixed. If \code{TRUE} then array of mixed string/numeric types will be promoted to all -string values and returned as an atonic character vector. Set this to \code{TRUE} +string values and returned as an atomic character vector. Set this to \code{TRUE} if you want to emulate the behaviour of \code{jsonlite::fromJSON()}} \item{yyjson_read_flag}{integer vector of internal \code{yyjson} diff --git a/man/read_ndjson_file.Rd b/man/read_ndjson_file.Rd index 01273b7..3a99dde 100644 --- a/man/read_ndjson_file.Rd +++ b/man/read_ndjson_file.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ndjson.R \name{read_ndjson_file} \alias{read_ndjson_file} -\title{Parse an ndjson file to a data.frame or list} +\title{Parse an NDJSON file to a data.frame or list} \usage{ read_ndjson_file( filename, @@ -35,11 +35,11 @@ The valid named options are identical to arguments to \code{\link[=opts_read_jso list or data.frame } \description{ -If reading as data.frame, each row of ndjson becomes a row in the data.frame. +If reading as data.frame, each row of NDJSON becomes a row in the data.frame. If reading as a list, then each row becomes an element in the list. } \details{ -If parsing ndjson to a data.frame it is usually better if the json objects +If parsing NDJSON to a data.frame it is usually better if the json objects are consistent from line-to-line. Type inference for the data.frame is done during initialisation by reading through \code{nprobe} lines. Warning: if there is a type-mismatch further into the file than it is probed, then you diff --git a/man/write_geojson_str.Rd b/man/write_geojson_str.Rd index b4f715a..4475c07 100644 --- a/man/write_geojson_str.Rd +++ b/man/write_geojson_str.Rd @@ -3,7 +3,7 @@ \name{write_geojson_str} \alias{write_geojson_str} \alias{write_geojson_file} -\title{Write SF to geojson string} +\title{Write SF to GeoJSON string} \usage{ write_geojson_str(x, opts = list(), ..., digits = -1) @@ -28,5 +28,5 @@ the floating point value should be written as-is (the default).} character string containing json } \description{ -Write SF to geojson string +Write SF to GeoJSON string } diff --git a/man/write_ndjson_file.Rd b/man/write_ndjson_file.Rd index 22805e4..a3782d6 100644 --- a/man/write_ndjson_file.Rd +++ b/man/write_ndjson_file.Rd @@ -3,7 +3,7 @@ \name{write_ndjson_file} \alias{write_ndjson_file} \alias{write_ndjson_str} -\title{Write list or data.frame object to ndjson} +\title{Write list or data.frame object to NDJSON} \usage{ write_ndjson_file(x, filename, opts = list(), ...) @@ -20,7 +20,7 @@ write_ndjson_str(x, opts = list(), ...) 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 +Write list or data.frame object to NDJSON } \examples{ \dontrun{