What is the quickest way to write out a large data frame as json in R?
I need to write a large data frame to a file as JSON in R. I am using the
rjson package. The approach below is quite slow...
for (i in 1:nrow(df)) {
write.table(toJSON(df[i,]),"[FILENAME]",
row.names=FALSE,col.names=FALSE,quote=FALSE,append=TRUE)
}
So I tried this:
write.table(toJSON(df),"FILENAME]",
row.names=FALSE,col.names=FALSE,quote=FALSE,append=TRUE)
Which chokes because toJSON() cannot handle a string that is of very long
length. So I would like to perhaps write out chunks of my data table at a
time. What is the recommended approach for this? If it involves split()
could you provide some psuedocode?
No comments:
Post a Comment