使用aws.s3
库从R写入S3存储桶的过程如下
s3write_using(iris, FUN = write.csv, object = "iris.csv", bucket = "some-bucket")
但是我无法选择工作。例如。 row.names=FALSE
我尝试了以下
s3write_using(iris, FUN = write.csv, object = "iris.csv", bucket = "some-bucket", opts = list(row.names=FALSE))
s3write_using(iris, FUN = write.csv, object = "iris.csv", bucket = "some-bucket", opts = list("row.names"=FALSE))
# Seen here: https://github.com/cloudyr/aws.s3/issues/200
s3write_using(iris, FUN = write.csv, object = "iris.csv", bucket = "some-bucket", opts=list(headers = c('row.names' = 'FALSE')))
以上都不是错误(甚至没有警告),但是生成的.csv
具有行名,而不应该这样
如何使用s3write_using
从R写入S3存储桶并指定row.names = FALSE
(或任何其他可选参数)?
答案 0 :(得分:1)
s3write_using
的手册说:
分别传递给put_object或save_object的可选其他参数。
因此,可选参数将传递给其他aws.s3函数,而不是write.csv
。
但是您始终可以定义自己的函数:
mywrite <- function(x, file) {
write.csv(x, file, row.names=FALSE)
}
然后使用此功能代替write.csv:
s3write_using(iris, FUN = mywrite, object = "iris.csv", bucket = "some-bucket")
您甚至可以创建一个函数生成器,该函数生成器返回一个环绕write.csv
并提供必要参数的函数:
customize.write.csv <- function(row.names=TRUE, ...) {
function(x, file) {
write.csv(x, file, row.names=row.names, ...)
}
}
您可以这样使用:
s3write_using(iris,
FUN = customize.write.csv(row.names=FALSE, dec=","),
object = "iris.csv",
bucket = "some-bucket")