You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for your great contribution to the R world, I am using jsonlite on a regular basis and it is a great tool. Nevertheless, I found a minor issue in the error reporting of fromJSON, which is slightly confusing in my oppinion, and you may change this easily, if you agree:
The function fromJSON checks, if input is NA (jsonlite_1.5):
if (!is.character(txt) &&!inherits(txt, "connection")) {
However, if I call fromJSON with a NA which was casted to a character, it won't (error messages translated from German, may not be excatly the original terms):
> fromJSON(NA)
Error: Argument 'txt' must be a JSON string, URL or file.
> fromJSON(as.character(NA))
Error in if (is.character(txt) && length(txt) == 1 && nchar(txt, type = "bytes") < :
Missing value, where TRUE/FALSE expected
What I would expect, is the following behaviour:
> fromJSON(NA)
Error: Argument 'txt' must be a JSON string, URL or file.
> fromJSON(as.character(NA))
Error: Argument 'txt' must be a JSON string, URL or file.
if (!is.character(txt) &&!inherits(txt, "connection")) {
by a NA check, something like:
if (is.null(txt) || is.na(txt) || (!is.character(txt) && !inherits(txt, "connection"))) {
I also added is.null, since this causes similar confusing error messages.
Feel free to use my suggested code, if you like, I would be happy to have clearer error messages in future. Thank you again
Stephan
The text was updated successfully, but these errors were encountered:
I'm getting this too.
In my case the cause of the issue was a single invalid character (some Unicode issue I think) in the source data provided by an API, which httr2::resp_body_json() would fail to read without an error. (resp_body_json uses jsonlite I believe).
Thank you for your great contribution to the R world, I am using jsonlite on a regular basis and it is a great tool. Nevertheless, I found a minor issue in the error reporting of
fromJSON
, which is slightly confusing in my oppinion, and you may change this easily, if you agree:The function
fromJSON
checks, if input isNA
(jsonlite_1.5):jsonlite/R/fromJSON.R
Line 86 in e5e6143
This works, as long as the input is not NA. Usually, NA is logical, so the line above will treat the situation:
jsonlite/R/fromJSON.R
Line 81 in e5e6143
However, if I call
fromJSON
with aNA
which was casted to a character, it won't (error messages translated from German, may not be excatly the original terms):What I would expect, is the following behaviour:
So, you should amend
jsonlite/R/fromJSON.R
Line 81 in e5e6143
NA
check, something like:I also added
is.null
, since this causes similar confusing error messages.Feel free to use my suggested code, if you like, I would be happy to have clearer error messages in future. Thank you again
Stephan
The text was updated successfully, but these errors were encountered: