代码之家  ›  专栏  ›  技术社区  ›  Regressor

如何将R数据帧写入谷歌云存储桶文件夹

  •  1
  • Regressor  · 技术社区  · 6 年前

    我想把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 ################################
    

    这会将数据帧加载到bucket my-bucket .

    现在我想把这个数据框保存到一个不同的文件夹结构中- my-bucket\my-folder\results.csv .如何将数据帧保存到GCS中的新路径?

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

    1 回复  |  直到 6 年前
        1
  •  0
  •   MarkeD    6 年前

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

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