Long string from System(Command) using jsonlite question

Really new to R so please forgive me if this is really basic.

I'm running a system command to query a string from a website that comes back in json text and then using the jsonlite library. The string is long and it puts it into multiple character arrays. Each array is 8095 characters. When I feed that into fromJSON it joins the character arrays with spaces which happen to fall in between numbers so the fromJSON parser fails.

>test <- system("...somecomand", intern = TRUE)
>str(test)
 chr [1:4] "{\"number\":52.55"|__truncated___...
>test_df <- fromJSON(test)
Error: parse error: after key and value, inside map, I expect ',' or '}'
          lume":36265,"datetime":159196 9500000},{"open":43.62,"high":
                     (right here) ------^

Where it indicates (right here) is where it added a space between numbers.

I tried adding the character arrays together with cat and paste. I haven't tried saving it to a file and I'm not sure if there is a way to stream it to the parser. I'm probably using strings/characters incorrectly. Appreciated if someone could point me in the right direction.

Thanks.

OK.... feel stupid now. I figured it out. Keeping it here in case anyone runs into the same problem as a beginner. Making some assumptions.

When I run the system() command the string data comes back in 8096 sized chunks giving me a chr array. I'm assuming this is because of some type of buffering when the data is returned. When I use fromJSON it is putting a space (or could be /n) when adding the arrays together to make a long string for parsing into JSON.

So this was just corrected using the paste() with collapse argument specified to create one long string instead. I must have used all kinds of options with the sep but never looked to collapse.

so now this works.

>test_df <- fromJSON(paste(test, collapse = ""))

I guess this is how to learn.... run into a problem, read, think, try, read, think, try.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.