googledrive (version 0.0.0.9000)

drive_download: Download a Drive file

Description

This function downloads a file from Google Drive. Native Google file types, such as Google Docs, Google Sheets, and Google Slides, must be exported to a conventional local file type. This can be specified:

  • explicitly via type

  • implicitly via the file extension of path

  • not at all, i.e. rely on default built into googledrive

To see what export file types are even possible, see the Drive API documentation. Returned dribble contains local path to downloaded file in local_path.

Usage

drive_download(file, path = NULL, type = NULL, overwrite = FALSE,
  verbose = TRUE)

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.

path

Character. Path for output file. If absent, the default file name is the file's name on Google Drive and the default location is working directory, possibly with an added file extension.

type

Character. Only consulted if file is a native Google file. Specifies the desired type of the downloaded 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.

overwrite

A logical scalar. If path already exists, do you want to overwrite it?

verbose

Logical, indicating whether to print informative messages (default TRUE).

Value

An object of class dribble, a tibble with one row per item.

Examples

Run this code
# NOT RUN {
## Upload a csv file into a Google Sheet
file <- drive_upload(
  drive_example("chicken.csv"),
  type = "spreadsheet"
  )

## Download Sheet as csv, explicit type
(downloaded_file <- drive_download(file, type = "csv"))

## See local path to new file
downloaded_file$local_path

## Download as csv, type implicit in file extension
drive_download(file, path = "my_csv_file.csv")

## Download with default name and type (xlsx)
drive_download(file)

## Clean up
unlink(c("chicken.csv", "chicken.csv.xlsx", "my_csv_file.csv"))
drive_rm(file)
# }

Run the code above in your browser using DataCamp Workspace