Skip to content

Commit f5c1d26

Browse files
committed
Bug fix found by Xavier re. another empty element of a list; R CMD check for CRAN to clear up compiler warnings; new version
1 parent eb5fd36 commit f5c1d26

File tree

8 files changed

+47
-26
lines changed

8 files changed

+47
-26
lines changed

.Rbuildignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ purdy.R
1212
roebuck.R
1313
json-asIS-withlevel
1414
src/Makevars$
15-
1615
Changes.xml
1716
intName.R
1817
streaming.R
@@ -21,11 +20,9 @@ tests.R
2120
testStream.R
2221
dataframe.R
2322
leak.R
24-
utf.*
2523
jsonText.rda
2624
foo.html
2725
Web
2826
bigFile.R
29-
stream.R
3027
experiments
31-
28+
utfTest.*

DESCRIPTION

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
Package: RJSONIO
2-
Version: 1.2-1
2+
Version: 1.3-0
33
Title: Serialize R objects to JSON, JavaScript Object Notation
44
Description: This is a package that allows conversion to and from
55
data in Javascript object notation (JSON) format.
66
This allows R objects to be inserted into Javascript/ECMAScript/ActionScript code
77
and allows R programmers to read and convert JSON content to R objects.
8-
This is an alternative to rjson package. That version was too slow for converting large R objects to JSON
9-
and is not extensible, but a very useful prototype. It is fast for parsing.
10-
This package uses methods, vectorized operations and C code and callbacks to R functions
11-
for deserializing JSON objects to R.
12-
Verison 0.4 of this package uses a new native parser, implements the transformation code
13-
in C and allocates memory efficiently (rather than concatenating because of event driven parsing).
14-
The result is a significantly faster parsing of large JSON documents.
15-
Note: The C code comes from www.json.org and is licensed under essentially the BSD license.
8+
This is an alternative to rjson package. Originally, that was too slow for converting large R objects to JSON
9+
and was not extensible. rjson's performance is now similar to this package, and perhaps slightly faster in some cases.
10+
This package uses methods and is readily extensible by defining methods for different classes,
11+
vectorized operations, and C code and callbacks to R functions for deserializing JSON objects to R.
12+
The two packages intentionally share the same basic interface. This package (RJSONIO) has many additional
13+
options to allow customizing the generation and processing of JSON content.
14+
This package uses libjson rather than implementing yet another JSON parser. The aim is to support
15+
other general projects by building on their work, providing feedback and benefit from their ongoing development.
16+
Note: The C code for parsing JSON comes from www.json.org and is licensed under essentially the BSD license.
1617
See the notice in src/JSON_parser.c
1718
The libjson code is on sourceforge.net, but does not yet have a license.
1819
libjson was written and is maintained and developed by Johnathan Wallace.

R/json.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ setMethod("toJSON", "matrix",
264264
setMethod("toJSON", "list",
265265
function(x, container = isContainer(x, asIs, .level), collapse = "\n", ..., .level = 1L, .withNames = length(x) > 0 && length(names(x)) > 0, .na = "null", .escapeEscapes = TRUE, pretty = FALSE, asIs = NA, .inf = " Infinity") {
266266
# Degenerate case.
267-
#browser()
267+
browser()
268268
if(length(x) == 0) {
269269
# x = structure(list(), names = character()) gives {}
270270
return(if(is.null(names(x))) "[]" else "{}")
@@ -280,7 +280,9 @@ setMethod("toJSON", "list",
280280
if(!container)
281281
return(els)
282282

283-
els = unlist(els)
283+
# els = unlist(els)
284+
w = sapply(els, length) == 0
285+
els[w] = "[]" # or "" or "null"
284286

285287
if(.withNames)
286288
paste(sprintf("{%s", collapse),

Web/index.html.in

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ string, key, start or end of an array or object) is found
4242
in the JSON content.
4343
</p>
4444

45-
<p> This package is motivated by the need to export R objects for use
45+
<p> This package was motivated by the need to export R objects for use
4646
in creating dynamic graphics for the Web via SVG and Flash/FLEX.
47-
Initially, we used Alex Couture-Beil's <a
47+
Since then, JSON has become a prominent format with many uses.
48+
Alex Couture-Beil's <a
4849
href="http://cran.r-project.org/web/packages/rjson/index.html">rjson</a>
49-
package. However, that does not use S4/S3 methods and so is not
50-
readily extensible, but still useful. Unfortunately, it does not used
51-
vectorized operations and so is too slow for non-trivial
52-
data. Similarly, for reading JSON data into R, it is somewhat slow and
53-
so does not scale to large data, should this be an issue.
50+
package is another mechanism in R for reading and writing JSON
51+
content. However, that does not use S4/S3 methods and so is not
52+
readily extensible, but still useful.
5453
</p>
5554

5655
<h2>Documentation</h2>
@@ -64,8 +63,8 @@ so does not scale to large data, should this be an issue.
6463

6564
<hr>
6665
<address><a href="http://www.stat.ucdavis.edu/~duncan">Duncan Temple Lang</a>
67-
<a href=mailto:[email protected]>&lt;duncan@wald.ucdavis.edu&gt;</a></address>
66+
<a href=mailto:[email protected]>&lt;duncan@r-project.org&gt;</a></address>
6867
<!-- hhmts start -->
69-
Last modified: Sun Aug 9 11:53:44 PDT 2009
68+
Last modified: Mon May 19 09:26:38 PDT 2014
7069
<!-- hhmts end -->
7170
</body> </html>

src/libjson/JSONOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
* your json into a stream, which will automatically hit a callback when full nodes are
118118
* completed
119119
*/
120-
#define JSON_STREAM
120+
// #define JSON_STREAM
121121

122122

123123
/*

src/libjson/Source/JSONDefs/GNU_C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef JSON_GNU_C_HEADER
2-
#define JSON_GUN_C_HEADER
2+
#define JSON_GNU_C_HEADER
33

44
#ifdef __GNUC__
55

src/rlibjson.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ R_json_parse(SEXP str)
1414
return(R_MakeExternalPtr(node, Rf_install("JSONNODE"), R_NilValue));
1515
}
1616

17+
void
18+
jsonErrorHandler(const json_char *foo)
19+
{
20+
PROBLEM "json error handler: %s", foo
21+
ERROR;
22+
}
23+
1724
SEXP
1825
R_fromJSON(SEXP r_str, SEXP simplify, SEXP nullValue, SEXP simplifyWithNames, SEXP encoding,
1926
SEXP r_stringFun, SEXP r_str_type)
@@ -36,6 +43,11 @@ R_fromJSON(SEXP r_str, SEXP simplify, SEXP nullValue, SEXP simplifyWithNames, SE
3643
} else
3744
r_stringFun = NULL;
3845

46+
#if 0
47+
register_debug_callback(jsonErrorHandler);
48+
#else
49+
#pragma message("activate the debug_callback")
50+
#endif
3951
node = json_parse(str);
4052
ans = processJSONNode(node, json_type(node), INTEGER(simplify)[0], nullValue, LOGICAL(simplifyWithNames)[0],
4153
INTEGER(encoding)[0], r_stringFun, str_fun_type);

tests/toJSON.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ e = new.env(); e$a = 1:10; e$bc = letters[1:3]
99
cat(toJSON(e, pretty = TRUE))
1010

1111

12+
a = list(x=1, y=character(0))
13+
fromJSON( toJSON( a ) )
14+
a = list(x=1, y=character(0), b = 1)
15+
fromJSON( toJSON( a ) )
16+
17+
18+
a = list(x = vector(), y = 123, z = "allo")
19+
fromJSON(toJSON(a))
20+
21+

0 commit comments

Comments
 (0)