rii*_*ic0 4 r azure azure-blob-storage
我正在尝试将 R 中的数据帧转换为 Azure Blob 存储上的 CSV 文件。我使用了AzureStor包,但它无法正确转换数据帧。我期望 16 列包含数据,但它返回一列,其中所有数据随机拆分到行中。
我使用了下面的 R 代码:
library(AzureStor)
bl_endp_key <- storage_endpoint("url", key="key")
cont <- storage_container(bl_endp_key, "containername")
csv <- serialize(dataframe, connection = NULL, ascii = TRUE)
con <- rawConnection(csv)
upload_blob(cont, src=con, dest="output.csv")
Run Code Online (Sandbox Code Playgroud)
谁能告诉我需要更改什么,或者给我示例代码来说明您如何成功做到这一点?
提前致谢!
这是我的示例代码,它运行良好。
library(AzureStor)
df <- data.frame(Column1 = c('Value 1', 'Value 2', 'Value 3'),
Column2 = c('Value 1', 'Value 2', 'Value 3'))
account_endpoint <- "https://<your account name>.blob.core.windows.net"
account_key <- "<your account key>"
container_name <- "<your container name>"
bl_endp_key <- storage_endpoint(account_endpoint, key=account_key)
cont <- storage_container(bl_endp_key, container_name)
w_con <- textConnection("foo", "w")
write.csv(df, w_con)
r_con <- textConnection(textConnectionValue(w_con))
close(w_con)
upload_blob(cont, src=r_con, dest="df.csv")
close(con)
Run Code Online (Sandbox Code Playgroud)
内容df.csv如下。
"","Column1","Column2"
"1","Value 1","Value 1"
"2","Value 2","Value 2"
"3","Value 3","Value 3"
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你。