Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R从aws s3提取多个json文档_R - Fatal编程技术网

使用R从aws s3提取多个json文档

使用R从aws s3提取多个json文档,r,R,我目前正在尝试从aws S3和R中提取文档。我成功地提取了一个文档,并用该文档创建了一个数据框架。我希望能够提取eventstore/footballStats/的多个子文件夹中的多个文档 代码演示了正在提取的1个有效文档。 install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat")) # runs an update for aws S3 library(aws.s3) # Set cre

我目前正在尝试从aws S3和R中提取文档。我成功地提取了一个文档,并用该文档创建了一个数据框架。我希望能够提取eventstore/footballStats/的多个子文件夹中的多个文档

代码演示了正在提取的1个有效文档。

install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat")) # runs an update for aws S3
library(aws.s3)

# Set credentials for S3 ####
Sys.setenv("AWS_ACCESS_KEY_ID" = "KEY","AWS_SECRET_ACCESS_KEY" = "AccessKey")  


# Extracts 1 document raw vector representation of an S3 documents ####
DataVector <-get_object("s3://eventstore/footballStats/2017-04-22/13/01/doc1.json") 

是否有我应该使用的替代r软件包?或者函数get_object()只适用于1个文档,而我应该使用aws.s3库中的另一个函数?

根据Drj和Thomas的提示,我能够解决这个问题

### Displays Buckets in s3####
bucketlist()

### Builds a dataframe of the files in a bucket###
dfBucket <- get_bucket_df('eventstore', 'footballStats/2017-04-22/')

# creates path based on data in bucket
path <- dfBucket$Key

### Extracts all data into values ####
s3Data <- NULL
for (lineN in path) {
  url <- paste('s3://eventstore/',lineN, sep= "") 
  s3Vector <- get_object(url)
  s3Value <- rawToChar(s3Vector)
  s3Data <- c(s3Data, s3Value)
}
###在s3中显示存储桶####
bucketlist()
###在bucket中构建文件的数据帧###

dfBucket关于
cloudyr
项目的文档不是很清楚,因此最好的办法可能是一次获取一个对象。如果对象太多,从bucket中获取对象列表(
cloudyr
提到了它),然后使用
paste
在列表上迭代,为每个bucket创建一个URL,然后
get_object
。不能将全局或模式传递给
get_object()
。它将只返回一个对象,因此@Drj建议使用
get_bucket()
列出所有对象,然后迭代对象键,将每个键传递给
get_object()
。谢谢@Drj。我能解决这个问题。
### Displays Buckets in s3####
bucketlist()

### Builds a dataframe of the files in a bucket###
dfBucket <- get_bucket_df('eventstore', 'footballStats/2017-04-22/')

# creates path based on data in bucket
path <- dfBucket$Key

### Extracts all data into values ####
s3Data <- NULL
for (lineN in path) {
  url <- paste('s3://eventstore/',lineN, sep= "") 
  s3Vector <- get_object(url)
  s3Value <- rawToChar(s3Vector)
  s3Data <- c(s3Data, s3Value)
}