我想将R数据帧写入Google Cloud Storage存储桶。我在R中使用googleCloudStorageR
库,这是我的代码-
################### 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
中。
现在,我想保存相同的数据帧,但保存到不同的文件夹结构,例如-my-bucket\my-folder\results.csv
。如何将数据框保存到GCS中的此新路径?
https://cran.r-project.org/web/packages/googleCloudStorageR/googleCloudStorageR.pdf
答案 0 :(得分:0)
您将名称更改为文件夹结构(unix样式),因此更改最后一行:
# Upload that file to the global bucket
gcs_upload(file = results , name = "my-folder/results.csv")