drive_put {googledrive} | R Documentation |
PUT new media into a Drive file
Description
PUTs new media into a Drive file, in the HTTP sense:
If the file already exists, we replace its content.
If the file does not already exist, we create a new file.
This is a convenience wrapper around drive_upload()
and
drive_update()
. In pseudo-code:
target_filepath <- <determined from `path`, `name`, and `media`> hits <- <get all Drive files at target_filepath> if (no hits) { drive_upload(media, path, name, type, ...) } else if (exactly 1 hit) { drive_update(hit, media, ...) } else { ERROR }
Usage
drive_put(
media,
path = NULL,
name = NULL,
...,
type = NULL,
verbose = deprecated()
)
Arguments
media |
Character, path to the local file to upload. |
path |
Specifies target destination for the new file on Google
Drive. Can be an actual path (character), a file id marked with
If If |
name |
Character, new file name if not specified as part of
|
... |
Named parameters to pass along to the Drive API. Has dynamic dots semantics. You can affect the metadata of the target file by
specifying properties of the Files resource via |
type |
Character. If |
verbose |
This logical argument to
individual googledrive functions is deprecated. To globally suppress
googledrive messaging, use |
Value
An object of class dribble
, a tibble with one row per file.
Examples
# create a local file to work with
local_file <- tempfile("drive_put_", fileext = ".txt")
writeLines(c("beginning", "middle"), local_file)
# PUT to a novel filepath --> drive_put() delegates to drive_upload()
file <- drive_put(local_file)
# update the local file
cat("end", file = local_file, sep = "\n", append = TRUE)
# PUT again --> drive_put() delegates to drive_update()
file <- drive_put(local_file)
# create a second file at this filepath
file2 <- drive_create(basename(local_file))
# PUT again --> ERROR
drive_put(local_file)
# Clean up
drive_find("drive_put_.+[.]txt") %>% drive_rm()
unlink(local_file)