s3read_using: Custom read and write

Description Usage Arguments Value See Also Examples

View source: R/s3read_using.R

Description

Read/write objects from/to S3 using a custom function

Usage

1
2
3
s3write_using(x, FUN, ..., object, bucket, opts = NULL)

s3read_using(FUN, ..., object, bucket, opts = NULL, filename = NULL)

Arguments

x

For s3write_using, a single R object to be saved via the first argument to FUN and uploaded to S3.

FUN

For s3write_using, a function to which x and a file path will be passed (in that order).

...

Additional arguments to FUN

object

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.

bucket

Character string with the name of the bucket, or an object of class “s3_bucket”.

opts

Optional additional arguments passed to put_object or save_object, respectively.

filename

Optional string, name of the temporary file that will be created. If not specified, tempfile() with the extension of the object is used.

Value

For s3write_using, a logical, invisibly. For s3read_using, the output of FUN applied to the file from object.

See Also

s3saveRDS, s3readRDS, put_object,get_object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
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)

## End(Not run)

aws.s3 documentation built on April 14, 2020, 5:15 p.m.