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.
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
NULL
(default), the appropriate reading function will be inferred based on the file's extension.- ...
Additional arguments to pass to the reading function
fun
.- root
S3 path of the project root. This serves as the reference point for all relative paths. When left as
NULL
, the root is automatically derived from thecloudfs.s3
field of the project's DESCRIPTION file.
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
if (FALSE) { # interactive()
# 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)
}