shortcut_create: Create a shortcut to a Drive file

View source: R/shortcut.R

shortcut_createR Documentation

Create a shortcut to a Drive file

Description

Creates a shortcut to the target Drive file, which could be a folder. A Drive shortcut functions like a symbolic or "soft" link and is primarily useful for creating a specific Drive user experience in the browser, i.e. to make a Drive file or folder appear in more than 1 place. Shortcuts are a relatively new feature in Drive; they were introduced when Drive stopped allowing a file to have more than 1 parent folder.

Usage

shortcut_create(file, path = NULL, name = NULL, overwrite = NA)

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

Target destination for the new shortcut, i.e. a folder or a shared drive. Can be given as an actual path (character), a file id or URL marked with as_id(), or a dribble. Defaults to your "My Drive" root folder. If path is a shortcut to a folder, it is automatically resolved to its target folder.

name

Character, new shortcut name if not specified as part of path. This will force path to be interpreted as a folder, even if it is character and lacks a trailing slash. By default, the shortcut starts out with the same name as the target file. As a consequence, if you want to use overwrite = TRUE or overwrite = FALSE, you must explicitly specify the shortcut's name.

overwrite

Logical, indicating whether to check for a pre-existing file at the targetted "filepath". The quotes around "filepath" refer to the fact that Drive does not impose a 1-to-1 relationship between filepaths and files, like a typical file system; read more about that in drive_get().

  • NA (default): Just do the operation, even if it results in multiple files with the same filepath.

  • TRUE: Check for a pre-existing file at the filepath. If there is zero or one, move a pre-existing file to the trash, then carry on. Note that the new file does not inherit any properties from the old one, such as sharing or publishing settings. It will have a new file ID. An error is thrown if two or more pre-existing files are found.

  • FALSE: Error if there is any pre-existing file at the filepath.

Note that existence checks, based on filepath, are expensive operations, i.e. they require additional API calls.

Value

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

See Also

Examples


# Target one of the official example files
(src_file <- drive_example_remote("chicken_sheet"))

# Create a shortcut in the default location with the default name
sc1 <- shortcut_create(src_file)
# This shortcut could now be moved, renamed, etc.

# Create a shortcut in the default location with a custom name
sc2 <- src_file %>%
  shortcut_create(name = "chicken_sheet_second_shortcut")

# Create a folder, then put a shortcut there, with default name
folder <- drive_mkdir("chicken_sheet_shortcut_folder")
sc3 <- src_file %>%
  shortcut_create(folder)

# Look at all these shortcuts
(dat <- drive_find("chicken_sheet", type = "shortcut"))

# Confirm the shortcuts all target the original file
dat <- dat %>%
  drive_reveal("shortcut_details")
purrr::map_chr(dat$shortcut_details, "targetId")
as_id(src_file)

# Clean up
drive_rm(sc1, sc2, sc3, folder)


googledrive documentation built on July 9, 2023, 7:04 p.m.