Read/write objects from/to S3 using a custom function
s3write_using(x, FUN, ..., object, bucket, opts = NULL)
s3read_using(FUN, ..., object, bucket, opts = NULL, filename = NULL)
For s3write_using
, a single R object to be saved via the first argument to FUN
and uploaded to S3.
For s3write_using
, a function to which x
and a file path will be passed (in that order).
Additional arguments to FUN
Character string with the object key, or an object of class “s3_object”. In most cases, if object
is specified as the latter, bucket
can be omitted because the bucket name will be extracted from “Bucket” slot in object
.
Character string with the name of the bucket, or an object of class “s3_bucket”.
Optional additional arguments passed to put_object
or save_object
, respectively.
Optional string, name of the temporary file that will be created. If not specified, tempfile()
with the extension of the object is used.
For s3write_using
, a logical, invisibly. For s3read_using
, the output of FUN
applied to the file from object
.
if (FALSE) { # \dontrun{
library("datasets")
# create bucket
b <- put_bucket("myexamplebucket")
# save a dataset to the bucket as a csv
if (require("utils")) {
s3write_using(mtcars, FUN = write.csv, object = "mtcars.csv", bucket = b)
}
# load dataset from the bucket as a csv
if (require("utils")) {
s3read_using(FUN = read.csv, object = "mtcars.csv", bucket = b)
}
# cleanup
delete_object(object = "mtcars.csv", bucket = b)
delete_bucket(bucket = b)
} # }