I'm trying to parse JSON contained in a dataframe column, some of which is corrupted. As a first step I want to identify the corrupted rows, and use that to subset the dataframe.
I'm using the trick from this post using c()
to populate the list (even though I know it's slow):
myRows <- c()
for (i in 1:nrow(myDataframe)) {
tryCatch({myDataframe$myJSONstring[i] %>%
fromJSON() %>%
length()},
error = function(e) {print(i); myRows <- c(myRows, i)})
}
However, this doesn't work. print(i)
works fine, but after running the loop myRows
is still just an empty list. Is there some restriction on what code can run in the error bit of a tryCatch?