From dea89ecdc51dfa2cd50c3df24c0a2da4d5afc397 Mon Sep 17 00:00:00 2001 From: mikefc Date: Mon, 8 Apr 2024 23:21:36 +0000 Subject: [PATCH] fix compilation warnings. update docs --- DESCRIPTION | 15 ++++++++------- NEWS.md | 5 +++++ README.Rmd | 16 +++++++++++++++- src/R-yyjson-parse.c | 4 ++-- src/geojson-parse.c | 4 ++-- src/ndjson-serialize.c | 8 ++++---- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be9e0ae..86e4157 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,18 +1,19 @@ Package: yyjsonr Type: Package -Title: Fast JSON Parser and Generator -Version: 0.1.18.9006 +Title: Fast JSON, NDJSON and GeoJSON Parser and Generator +Version: 0.1.18.9007 Authors@R: c( person("Mike", "Cheng", role = c("aut", "cre", 'cph'), email = "mikefc@coolbutuseless.com"), person("Yao", "Yuan", role = c("aut", "cph"), email = "ibireme@gmail.com", comment="Author of bundled yyjson")) Maintainer: Mike Cheng -Description: A fast JSON parser, generator and validator which converts JSON - data to/from R objects. The standard R data types are supported - (e.g. logical, numeric, integer) with configurable handling of NULL and NA - values. Data frames, atomic vectors and lists are all supported as data - containers translated to/from JSON. +Description: A fast JSON parser, generator and validator which converts JSON, + NDJSON and GeoJSON data to/from R objects. The standard R data types are + supported (e.g. logical, numeric, integer) with configurable handling of NULL + and NA values. Data frames, atomic vectors and lists are all supported as data + containers translated to/from JSON. GeoJSON data is read in as + 'simple features' objects. This implementation wraps the 'yyjson' 'C' library which is available from . License: MIT + file LICENSE diff --git a/NEWS.md b/NEWS.md index 795e6a4..47dc67a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,9 @@ +# yyjsonr 0.1.18.9007 2024-04-09 + +* Fix some compilation warnings. +* Update documentation. + # yyjsonr 0.1.18.9006 2024-04-02 * Bug fix for serializing `NA` in factors diff --git a/README.Rmd b/README.Rmd index 4f42aec..a6d4420 100644 --- a/README.Rmd +++ b/README.Rmd @@ -107,13 +107,27 @@ Note: Benchmarks were run on Apple M2 Mac. See files `man/benchmark/benchmark*. ## Installation -You can install from [GitHub](https://github.com/coolbutuseless/yyjsonr) with: +This package can be installed from CRAN + +``` r +install.packages('yyjsonr') +``` + + +You can install the latest development version from [GitHub](https://github.com/coolbutuseless/yyjsonr) with: ``` r # install.package('remotes') remotes::install_github('coolbutuseless/yyjsonr') ``` +Pre-built source/binary versions can also be installed from [r-universe](https://r-universe.dev) + +``` r +install.packages('yyjsonr', repos = c('https://coolbutuseless.r-universe.dev', 'https://cloud.r-project.org')) +``` + + Simple JSON example diff --git a/src/R-yyjson-parse.c b/src/R-yyjson-parse.c index 1edb384..c75ee93 100644 --- a/src/R-yyjson-parse.c +++ b/src/R-yyjson-parse.c @@ -209,10 +209,10 @@ double json_val_to_double(yyjson_val *val, parse_options *opt) { case YYJSON_TYPE_NUM: switch (yyjson_get_subtype(val)) { case YYJSON_SUBTYPE_UINT: - return yyjson_get_uint(val); + return (double)yyjson_get_uint(val); break; case YYJSON_SUBTYPE_SINT: - return yyjson_get_sint(val); + return (double)yyjson_get_sint(val); break; case YYJSON_SUBTYPE_REAL: return yyjson_get_real(val); diff --git a/src/geojson-parse.c b/src/geojson-parse.c index 384cbdb..c37c75b 100644 --- a/src/geojson-parse.c +++ b/src/geojson-parse.c @@ -234,7 +234,7 @@ SEXP geojson_as_sf(yyjson_val *val, geo_parse_options *opt, unsigned int depth); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ unsigned int calc_matrix_coord_type(yyjson_val *arr, geo_parse_options *opt) { unsigned int coord_bitset = 0; - unsigned int coord_type; + unsigned int coord_type = COORD_XY; yyjson_arr_iter row_iter = yyjson_arr_iter_with(arr); yyjson_val *row; while ((row = yyjson_arr_iter_next(&row_iter))) { @@ -497,7 +497,7 @@ SEXP parse_multilinestring(yyjson_val *obj, geo_parse_options *opt) { yyjson_arr_iter ring_iter = yyjson_arr_iter_with(linestrings); yyjson_val *coords; unsigned int ring_idx = 0; - unsigned int coord_type; + unsigned int coord_type = COORD_XY; while ((coords = yyjson_arr_iter_next(&ring_iter))) { coord_type = calc_matrix_coord_type(coords, opt); diff --git a/src/ndjson-serialize.c b/src/ndjson-serialize.c index 52f3d5f..45f6551 100644 --- a/src/ndjson-serialize.c +++ b/src/ndjson-serialize.c @@ -82,7 +82,7 @@ SEXP serialize_list_to_ndjson_str_(SEXP robj_, SEXP serialize_opts_) { // concatenate into single string for return to R unsigned int total_len = 1; // extra '1' for '\0' byte at end of string for (unsigned int idx = 0; idx < nelems; idx++) { - total_len += strlen(ndjson[idx]) + 1; // extra 1 for `\n' for each row. + total_len += (unsigned int)strlen(ndjson[idx]) + 1; // extra 1 for `\n' for each row. // Rprintf("Total length: %i\n", total_len); } char *total_str; @@ -91,7 +91,7 @@ SEXP serialize_list_to_ndjson_str_(SEXP robj_, SEXP serialize_opts_) { unsigned int pos = 0; for (unsigned int idx = 0; idx < nelems; idx++) { strcpy(total_str + pos, ndjson[idx]); - pos += strlen(ndjson[idx]); + pos += (unsigned int)strlen(ndjson[idx]); total_str[pos] = '\n'; pos++; } @@ -319,7 +319,7 @@ SEXP serialize_df_to_ndjson_str_(SEXP robj_, SEXP serialize_opts_) { // concatenate into single string for return to R unsigned int total_len = 1; // extra '1' for '\0' byte at end of string for (unsigned int row = 0; row < nrows; row++) { - total_len += strlen(ndjson[row]) + 1; // extra 1 for `\n' for each row. + total_len += (unsigned int)strlen(ndjson[row]) + 1; // extra 1 for `\n' for each row. // Rprintf("Total length: %i\n", total_len); } char *total_str; @@ -328,7 +328,7 @@ SEXP serialize_df_to_ndjson_str_(SEXP robj_, SEXP serialize_opts_) { unsigned int idx = 0; for (unsigned int row = 0; row < nrows; row++) { strcpy(total_str + idx, ndjson[row]); - idx += strlen(ndjson[row]); + idx += (unsigned int)strlen(ndjson[row]); if (row == nrows - 1) { total_str[idx] = '\0'; } else {