如何将R数据帧写入Google Cloud Storage存储桶文件夹 [英] How to write R dataframe to a Google Cloud Storage bucket folder

查看:87
本文介绍了如何将R数据帧写入Google Cloud Storage存储桶文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将R数据帧写入Google Cloud Storage存储桶.我在R中使用googleCloudStorageR库,这是我的代码-

I want to write R dataframe to Google Cloud Storage bucket. I am using googleCloudStorageR library in R and here is my code -

################### START ###############################

options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/cloud-platform")
# load the libraries
library("googleAuthR", lib.loc="/home/user/packages" )
library("googleCloudStorageR", lib.loc="/home/user/packages")
gar_gce_auth()


name <- c("john","doe")
id <- c(1,2)
results = as.data.frame(cbind(name,id))
print("writing results to GCS")

# Set bucket name
bucket <- "my-bucket"
gcs_global_bucket(bucket)
print("bucket set.")


# Upload that file to the global bucket
gcs_upload(file = results , name = "results.csv")

################## END ################################

这会将数据帧加载到存储区my-bucket中.

This loads the dataframe to bucket my-bucket.

现在,我想保存相同的数据帧,但是保存到不同的文件夹结构中,例如-my-bucket\my-folder\results.csv.如何将数据框保存到GCS中的此新路径?

Now I want to save this same dataframe but to a different folder structure, for example - my-bucket\my-folder\results.csv . How can I save the dataframe to this new path in GCS ?

https://cran.r-project.org/web /packages/googleCloudStorageR/googleCloudStorageR.pdf

推荐答案

您将名称更改为文件夹结构(unix样式),因此更改了最后一行:

You change the name to be your folder structure (unix style), so change the last line:

# Upload that file to the global bucket
gcs_upload(file = results , name = "my-folder/results.csv") 

这篇关于如何将R数据帧写入Google Cloud Storage存储桶文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆