I'm looking for a way to read a matrix containing an infinite value that is encoded in a JSON file into R. I'm currently getting the furthest using the RJSONIO library for this (rjson and rjsonlite produce an error in my case).
A minimal illustrative example is as follows: (EDIT: this example is not general enough, the method I'm looking for can handle non-finite values that are not generated in R as well)
> library("RJSONIO")
> M <- matrix(c(1:5, Inf), ncol=2, byrow=TRUE); M
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 Inf
> fromJSON(toJSON(M))
[[1]]
[1] 1 2
[[2]]
[1] 3 4
[[3]]
[[3]][[1]]
[1] 5
[[3]][[2]]
NULL
Executing this code will also produce a warning that the non-finite values may not be appropriately represented in JSON.
I'm wondering if there is a work-around to get the infinite values to be correctly represented during the file reading? I'm fine with the file being stored as a list after reading, but not with the last element not being a numeric vector.
Note that I'm not really looking for a post-processing method that converts the non-numeric vectors after having read the entire file: I already have this, but the actual files I'm working with are quite large and nested, so I prefer to not have to rerun through them.