drive_read_string: Read the content of a Drive file

Description Usage Arguments Value Examples

View source: R/drive_read.R

Description

These functions return the content of a Drive file as either a string or raw bytes. You will likely need to do additional work to parse the content into a useful R object.

drive_download() is the more generally useful function, but for certain file types, such as comma-separated values (MIME type text/csv), it can be handy to read data directly from Google Drive and avoid writing to disk.

Just as for drive_download(), native Google file types, such as Google Sheets or Docs, must be exported as a conventional MIME type. See the help for drive_download() for more.

Usage

1
2
3

Arguments

file

Something that identifies the file of interest on your Google Drive. Can be a name or path, a file id or URL marked with as_id(), or a dribble.

type

Character. Only consulted if file is a native Google file. Specifies the desired type of the exported file. Will be processed via drive_mime_type(), so either a file extension like "pdf" or a full MIME type like "application/pdf" is acceptable.

encoding

Passed along to httr::content(). Describes the encoding of the input file.

Value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# comma-separated values --> data.frame or tibble
(chicken_csv <- drive_example_remote("chicken.csv"))
chicken_csv %>%
  drive_read_string() %>%
  read.csv(text = .)

# Google Doc --> character vector
(chicken_doc <- drive_example_remote("chicken_doc"))
chicken_doc %>%
  # NOTE: we must specify an export MIME type
  drive_read_string(type = "text/plain") %>%
  strsplit(split = "(\r\n|\r|\n)") %>%
  .[[1]]

googledrive documentation built on July 8, 2021, 5:07 p.m.