1

通常,在从 Watson Studio 笔记本处理 IBM Cloud Object Storage 中的文件时,我需要将文件保存到笔记本本地文件系统,然后我可以从 R 函数访问它们。

Project-lib 允许我从云对象存储中检索文件作为字节数组,如何将字节数组保存到文件中?

library(projectLib)
project <- projectLib::Project$new(projectId="secret, projectToken="secret")
pc <- project$project_context

my.file <- project$get_file("myfile.csv.gz")

#
# Question: how do I save the file to disk ??
#

df = read.csv2("myfile.csv.gz", sep = "|",
                           colClasses=c("ASSETUNIT_GLOBALID"="character"))

我尝试使用save(),但这会破坏文件中的数据。

4

1 回答 1

1

R函数writeBin是我的解决方案:

library(projectLib)
project <- projectLib::Project$new(projectId="secret, projectToken="secret")
pc <- project$project_context

my.file <- project$get_file("myfile.csv.gz")

#
# writeBin was the solution :
#

writeBin(my.file, 'myfile.csv.gz', size = NA_integer_,
         endian = .Platform$endian, useBytes = TRUE)

df = read.csv2("myfile.csv.gz", sep = "|",
                           colClasses=c("ASSETUNIT_GLOBALID"="character"))
于 2018-07-17T10:12:18.010 回答