cloud_drive_read {cloudfs} | R Documentation |
Read a file from Google Drive
Description
Retrieves and reads a file from the project's Google Drive 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_drive_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 |
Google Drive ID or URL 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 Google Drive, 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 Google Drive folder and they contain the files mentioned
# below
cloud_drive_read("data/mtcars.csv")
cloud_drive_read("models/random_forest.rds")
cloud_drive_read("data/dm.sas7bdat", fun = haven::read_sas)