Serialises x according to the key's extension (or format) and
uploads it:
Usage
write_s3(
x,
key,
bucket = NULL,
...,
format = NULL,
content_type = NULL,
metadata = NULL,
headers = NULL,
config = s3_config()
)Arguments
- x
The object to write.
- key
Object key inside
bucket, or ans3://bucket/keyURL.- bucket
Bucket; defaults to the config's bucket (
S3PE_BUCKET).- ...
Passed to the writer (for example
pretty = TRUEfor JSON,na = ""for CSV).- format
One of
"csv","tsv","json","geojson","parquet","rds","xlsx","text","raw"; overrides the extension.- content_type
Content type to store with the object.
- metadata
Named character vector of user metadata, stored with the object as
x-amz-meta-<name>and returned byhead_s3().- headers
Named character vector of extra headers to send with the upload:
Cache-Control,Content-Disposition,Content-Encoding,x-amz-storage-class,x-amz-server-side-encryption, ... (x-amz-*headers are signed).- config
An
s3_config().
Details
| Extension | Writer | Accepts |
.csv, .csv.gz | readr::write_csv() | data frame |
.tsv, .tsv.gz | readr::write_tsv() | data frame |
.json | jsonlite::toJSON() (auto_unbox = TRUE, digits = NA) | anything jsonlite can encode |
.geojson | sf::st_write() for sf objects, else jsonlite | sf or list |
.parquet | nanoparquet::write_parquet() | data frame |
.rds | saveRDS() | anything |
.txt, .md, .html, ... | character (joined by newlines) | |
| anything else | raw vector, or character as text |
The content type is set from the extension unless content_type is
given. After the upload the server's ETag is compared with the MD5 of
what was sent. Bodies larger than the config's multipart_threshold
(64 MiB by default) go up as a multipart upload, part by part, aborted
on any failure.
Examples
if (FALSE) { # interactive()
write_s3(mtcars, "report/mtcars.csv", bucket = "my-bucket")
write_s3(list(generated_at = Sys.time()), "report/manifest.json", bucket = "my-bucket")
write_s3(readBin("figure1.png", "raw", 1e7), "s3://my-bucket/report/figure1.png")
write_s3(mtcars, "report/mtcars.csv", bucket = "my-bucket",
metadata = c(author = "ana"), headers = c("Cache-Control" = "max-age=3600"))
}