在 R 中用 json 文件指定公共文件夹的路径

specify the path to the common folder with json files in R

解析json,我可以使用这种方法

 library("rjson")
    json_file <- "https://api.coindesk.com/v1/bpi/currentprice/USD.json"
    json_data <- fromJSON(paste(readLines(json_file), collapse=""))

但是如果我想使用一组 json 文件怎么办 它位于

json_file<-"C:/myfolder/"

如何解析此文件夹中的 data.frame 所有 json 文件? (有 1000 个文件)?

缺少很多信息,但这可能有用.. 我使用 pblapply 获得了一个不错的进度条(因为你提到了 >1000 个文件)。

我从未将下面的解决方案用于 JSON 文件(没有使用 JSON 的经验),但它在 .csv 和 .xls 文件(当然具有不同的读取功能)上工作完美.. 所以我希望它也能与 JSON 一起使用。

library(data.table)
library(pbapply)
library(rjson)

folderpath <- "C:\myfolder\"
filefilter <- "*.json$"

#set paramaters as needed
f <- list.files( path = folderpath,
                 pattern = filefilter,
                 full.names = TRUE,
                 recursive = FALSE )

#read all files to a list
f.list <- pblapply( f, function(x) fromJSON( file = x ) )

#join lists together
dt <- data.table::rbindlist( f.list )