.json 文件太大,无法在 R 中用 rjson 打开

.json file is too large to be opened in R with rjson

我有一个 5.1 GB json 文件,我想使用 rjson 在 R 中读取该文件。之后我想从中构建一个数据框,但是它不会加载,因为大小太大。

有什么办法解决这个问题吗?

感谢您的帮助=)

Nina,我建议你使用 jsonlite 包而不是 rjson

library(jsonlite)
your_json <- "your_path.json"
unpacked_json <- jsonlite::stream_in(textConnection(readLines(your_json, n=100000)),verbose=F)

这里你限制页面大小让IDE正确读取你的JSON文件。有关更多信息,我还建议您对此主题进行一些研究:

  1. https://community.rstudio.com/t/how-to-read-large-json-file-in-r/13486
  2. Reading a huge json file in R , issues

我确信有时处理文档真的很难(和其他所有人一样,我们很懒惰);我自己不喜欢阅读 doc-n,但我强烈建议您熟悉 jsonlite 文档和插图。这是 CRAN link:https://cran.r-project.org/web/packages/jsonlite/index.html