cloud_s3_read {cloudfs} | R Documentation |
Read a file from S3
Description
Retrieves and reads a file from the project's S3 folder. By default, the function attempts to determine the appropriate reading function based on the file's extension. However, you can specify a custom reading function if necessary.
Usage
cloud_s3_read(file, fun = NULL, ..., root = NULL)
Arguments
file |
Path to a file relative to project folder root. Can contain only letters, digits, '-', '_', '.', spaces and '/' symbols. |
fun |
A custom reading function. If |
... |
Additional arguments to pass to the reading function |
root |
S3 path of the project root. This serves as the reference point
for all relative paths. When left as |
Value
The content of the file read from S3, with additional attributes containing metadata about the file.
Default reading functions
Here's how we identify a reading function based on file extension
-
.csv
: readr::read_csv -
.json
: jsonlite::read_json -
.rds
: base::readRDS -
.sav
: haven::read_sav -
.xls
: cloud_read_excel -
.xlsx
: cloud_read_excel -
.xml
: xml2::read_xml
Examples
# provided there are folders called "data" and "models" in the root of your
# project's main S3 folder and they contain the files mentioned below
cloud_s3_read("data/mtcars.csv")
cloud_s3_read("models/random_forest.rds")
cloud_s3_read("data/dm.sas7bdat", fun = haven::read_sas)