## A complex R object
Robj <- structure(list(
a = as.double(c(1:5, 6)),
LETTERS,
c = c(c1 = 4.5, c2 = 7.8, c3 = Inf, c4 = -Inf, NA, c6 = NaN),
c(TRUE, FALSE, NA),
e = factor(c("a", "b", "a")),
f = "this is a \"string\"\nwith\tspecial chars",
g = matrix(rnorm(4), ncol = 2),
`h&'$@` = data.frame(x = 1:3, y = rnorm(3),
fact = factor(c("b", "a", "b"))),
i = Sys.Date(),
j = list(1:5, y = "another item")),
comment = "My comment\n\"",
anAttrib = 1:10,
anotherAttrib = list(TRUE, y = 1:4))
## Convert to simplest RJSON, without attributes
Rjson1 <- toRjson(Robj)
Rjson1
evalRjson(Rjson1)
## More complex RJSON, with attributes
Rjson2 <- toRjson(Robj, TRUE)
Rjson2
Robj2 <- evalRjson(Rjson2)
Robj2
## Numbers near equivalence comparison (note: identical(Robj, Robj2) is FALSE)
all.equal(Robj, Robj2)
rm(Robj, Robj2, Rjson1, Rjson2)
Run the code above in your browser using DataLab