0

It was all working fine but then suddenly one day I started getting this error. I've a json field in DB table and i'm trying to parse it

ahoy_prop <- jsonlite::stream_in(textConnection(ahoy_events_acc$properties, encoding = "UTF-8"))

But its showing this error now -

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 1, 0
Abhi
  • 55
  • 3

1 Answers1

2

It's hard to tell without an example text, but here's a way to find which of the elements is causing a parsing problem.

vec <- c('{"a":[1],"b":[2,3]}', '{', '')
out <- lapply(vec, function(z) try(jsonlite::stream_in(textConnection(z, encoding="UTF-8")), silent=TRUE))
#  Imported 1 records. Simplifying...
#  Imported 0 records. Simplifying...

which(sapply(out, inherits, "try-error"))
# [1] 2
vec[2]
# [1] "{"
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • I did that ``` ahoy_prop <- lapply(ahoy_events_acc$properties, function(z) try(jsonlite::stream_in(textConnection(z, encoding = "UTF-8")), silent=TRUE)) ``` And strangely it didn't show any error but when I'm counting the rows and columns it coming null but when I'm looking at dataframe its showing a large list – Abhi Oct 23 '20 at 01:50
  • `try(..., silent=TRUE)` specifically hides the error. Are you saying that `which(sapply(ahoy_prop, inherits, "try-error"))` returns `logical(0)`? – r2evans Oct 23 '20 at 02:58
  • btw, for formatting, triple backticks (`\`\`\``) only do something special in questions/answers, not in comments. The only thing you can do in comments is use *inline code*, with single backticks. For example, my `try(..., silent=TRUE)` is typed in as `\`try(..., silent=TRUE)\`` :-) – r2evans Oct 23 '20 at 03:01
  • I tried that and when I run which(sapply(ahoy_prop, inherits, "try-error")), it shows integer(0) – Abhi Nov 07 '20 at 11:24
  • To me, that suggests that your input is broken and/or not what you think. I can't really help with that since your question is not reproducible. It works with my data, so I believe the premise works. Please read suggestions on how to make a question reproducible: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info (and then please edit your question). Thanks! – r2evans Nov 07 '20 at 14:25