Error in fromJSON (paste (raw.data, collapse = "")): unclosed string
I am using the R package rjson
to download weather data from Wunderground.com. Often I leave the program to run, and there is no problem as the data is collected in order. However, often the program stops and I get the following error message:
Error in fromJSON(paste(raw.data, collapse = "")) : unclosed string
In addition: Warning message:
In readLines(conn, n = -1L, ok = TRUE) :
incomplete final line found on 'http://api.wunderground.com/api/[my_API_code]/history_20121214pws:1/q/pws:IBIRMING7.json'
Does anyone know what this means and how I can avoid this since it stops my program from collecting data as I would like?
Many thanks,
Ben
source to share
I can repair the error with a package rjson
.
Here's an example that works.
rjson::fromJSON('{"x":"a string"}')
# $x
# [1] "a string"
If we omit the double quote from the value x
, then we get an error message.
rjson::fromJSON('{"x":"a string}')
# Error in rjson::fromJSON("{\"x\":\"a string}") : unclosed string
The package RJSONIO
behaves somewhat differently. Instead of throwing an error, it silently returns NULL
.
RJSONIO::fromJSON('{"x":"a string}')
# $x
# NULL
source to share