Skip to content

Retrieves the metadata for the Drive file that a shortcut refers to, i.e. the shortcut's target. The returned dribble has the usual columns (name, id, drive_resource), which refer to the target. It will also include the columns name_shortcut and id_shortcut, which refer to the original shortcut. There are 3 possible scenarios:

  1. file is a shortcut and user can drive_get() the target. All is simple and well.

  2. file is a shortcut, but drive_get() fails for the target. This can happen if the user can see the shortcut, but does not have read access to the target. It can also happen if the target has been trashed or deleted. In such cases, all of the target's metadata, except for id, will be missing. Call drive_get() on a problematic id to see the specific error.

  3. file is not a shortcut. name_shortcut and id_shortcut will both be NA.

Usage

shortcut_resolve(file)

Arguments

file

Something that identifies the file(s) of interest on your Google Drive. Can be a character vector of names/paths, a character vector of file ids or URLs marked with as_id(), or a dribble.

Value

An object of class dribble, a tibble with one row per file. Extra columns name_shortcut and id_shortcut refer to the original shortcut.

Examples

# Create a file to make a shortcut to
file <- drive_example_remote("chicken_sheet") %>%
  drive_cp(name = "chicken-sheet-for-shortcut")
#> Original file:
#>chicken_sheet <id: 1SeFXkr3XdzPSuWauzPdN-XnaryOYmZ7sFiUF5t-wSVU>
#> Copied to file:
#>chicken-sheet-for-shortcut
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>

# Create a shortcut
sc1 <- file %>%
  shortcut_create(name = "shortcut-1")
#> Created Drive file:
#>shortcut-1 <id: 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz>
#> With MIME type:
#>application/vnd.google-apps.shortcut

# Create a second shortcut by copying the first
sc1 <- sc1 %>%
  drive_cp(name = "shortcut-2")
#> Original file:
#>shortcut-1 <id: 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz>
#> Copied to file:
#>shortcut-2 <id: 18UGke5J1cMScXrUqqxIPSSjKH_t7lR9c>

# Get the shortcuts
(sc_dat <- drive_find("-[12]$", type = "shortcut"))
#> # A dribble: 2 × 3
#>   name       id                                drive_resource   
#>   <chr>      <drv_id>                          <list>           
#> 1 shortcut-2 18UGke5J1cMScXrUqqxIPSSjKH_t7lR9c <named list [32]>
#> 2 shortcut-1 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz <named list [32]>

# Resolve them
(resolved <- shortcut_resolve(sc_dat))
#>  Resolved 2 shortcuts found in 2 files:
#>shortcut-2 <id: 18UGke5J1cMScXrUqqxIPSSjKH_t7lR9c> ->
#>   chicken-sheet-for-shortcut
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>
#>shortcut-1 <id: 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz> ->
#>   chicken-sheet-for-shortcut
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>
#> # A dribble: 2 × 5
#>   name                   id       name_shortcut id_shortcut drive_resource
#>   <chr>                  <drv_id> <chr>         <drv_id>    <list>        
#> 1 chicken-sheet-for-sho… 1upU5T-… shortcut-2    18UGke5…    <named list>  
#> 2 chicken-sheet-for-sho… 1upU5T-… shortcut-1    1xGNFmT…    <named list>  

resolved$id
#> <drive_id[2]>
#> [1] 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q
#> [2] 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q
file$id
#> <drive_id[1]>
#> [1] 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q

# Delete the target file
drive_rm(file)
#> File deleted:
#>chicken-sheet-for-shortcut
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>

# (Try to) resolve the shortcuts again
shortcut_resolve(sc_dat)
#>  Resolved 0 of 2 shortcuts found in 2 files:
#>shortcut-2 <id: 18UGke5J1cMScXrUqqxIPSSjKH_t7lR9c> -> NA
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>
#>shortcut-1 <id: 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz> -> NA
#>   <id: 1upU5T-g1ZIKJWs9KENlriViNxj18y5SXfk-p1bpRR3Q>
#> # A dribble: 2 × 5
#>   name  id       name_shortcut id_shortcut drive_resource  
#>   <chr> <drv_id> <chr>         <drv_id>    <list>          
#> 1 NA    1upU5T-… shortcut-2    18UGke5…    <named list [3]>
#> 2 NA    1upU5T-… shortcut-1    1xGNFmT…    <named list [3]>
# No error, but resolution is unsuccessful due to non-existent target

# Clean up
drive_rm(sc_dat)
#> Files deleted:
#>shortcut-2 <id: 18UGke5J1cMScXrUqqxIPSSjKH_t7lR9c>
#>shortcut-1 <id: 1xGNFmT3EK9iWHIY39zSJlKRkHB1XU-Oz>