【问题标题】:how to save a csv file to cloud object storage using project-lib?如何使用 project-lib 将 csv 文件保存到云对象存储?
【发布时间】:2018-12-25 00:56:08
【问题描述】:
我有一个已写入笔记本文件系统的 csv 文件:
# read csv from object storage
df = read.csv2( ... )
# do some operations ...
# save new csv to notebook filesystem
file.remove('example.csv')
write.csv(df, file = "example.csv")
如何将此文件复制到项目的云对象存储中?
【问题讨论】:
标签:
r
ibm-cloud
object-storage
watson-studio
project-lib
【解决方案1】:
这对我有用:
# import projectLib
library(projectLib)
project <- projectLib::Project$new(projectId="secret, projectToken="secret")
# get the file size:
csv.size = file.size('example.csv')
# read the file as a byte array
bytes.to.save = readBin('example.csv', 'raw', n = csv.size, size = NA_integer_,
signed = TRUE, endian = .Platform$endian)
# save the file to cloud object storage
project$save_data("example.csv", bytes.to.save, overwrite = TRUE)