Skip to content

Commit

Permalink
fix compilation warnings. update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Apr 8, 2024
1 parent c77b451 commit dea89ec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Yao", "Yuan", role = c("aut", "cph"), email = "[email protected]",
comment="Author of bundled yyjson"))
Maintainer: Mike Cheng <[email protected]>
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 <https://github.com/ibireme/yyjson>.
License: MIT + file LICENSE
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 15 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/R-yyjson-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/geojson-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/ndjson-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit dea89ec

Please sign in to comment.