Skip to content

Converts various representations of Google Drive files into a dribble, the object used by googledrive to hold Drive file metadata. Files can be specified via:

  • File path. File name is an important special case.

  • File id. Mark with as_id() to distinguish from file path.

  • Data frame or dribble. Once you've successfully used googledrive to identify the files of interest, you'll have a dribble. Pass it into downstream functions.

  • List representing Files resource objects. Mostly for internal use.

This is a generic function.

For maximum clarity, get your files into a dribble (or capture file id) as early as possible. When specifying via path, it's best to include the trailing slash when you're targeting a folder. If you want the folder foo, say foo/, not foo.

Some functions, such as drive_cp(), drive_mkdir(), drive_mv(), and drive_upload(), can accept the new file or folder name as the last part of path, when name is not given. But if you say a/b/c (no trailing slash) and a folder a/b/c/ already exists, it's unclear what you want. A file named c in a/b/ or a file with default name in a/b/c/? You get an error and must make your intent clear.

Usage

as_dribble(x, ...)

Arguments

x

A vector of Drive file paths, a vector of file ids marked with as_id(), a list of Files Resource objects, or a suitable data frame.

...

Other arguments passed down to methods. (Not used.)

Examples

# create some files for us to re-discover by name or filepath
alfa <- drive_create("alfa", type = "folder")
#> Created Drive file:
#>alfa <id: 1PpWsFCmIZG7eybIDS-s_c0rQmJcoQlbd>
#> With MIME type:
#>application/vnd.google-apps.folder
bravo <- drive_create("bravo", path = alfa)
#> Created Drive file:
#>bravo <id: 1zHMOzXdEVlW3GxvaKKzAXzI_XegJjdch>
#> With MIME type:
#>application/octet-stream

# as_dribble() can work with file names or paths
as_dribble("alfa")
#> # A dribble: 1 × 4
#>   name  path  id                                drive_resource   
#>   <chr> <chr> <drv_id>                          <list>           
#> 1 alfa  alfa/ 1PpWsFCmIZG7eybIDS-s_c0rQmJcoQlbd <named list [33]>
as_dribble("bravo")
#> # A dribble: 2 × 4
#>   name  path  id                                drive_resource   
#>   <chr> <chr> <drv_id>                          <list>           
#> 1 bravo bravo 1zHMOzXdEVlW3GxvaKKzAXzI_XegJjdch <named list [39]>
#> 2 bravo bravo 1Lbnr5CXFtJocrr-u3MIRBO8zbkvkUfXJ <named list [39]>
as_dribble("alfa/bravo")
#> # A dribble: 1 × 4
#>   name  path         id                                drive_resource   
#>   <chr> <chr>        <drv_id>                          <list>           
#> 1 bravo ~/alfa/bravo 1zHMOzXdEVlW3GxvaKKzAXzI_XegJjdch <named list [39]>
as_dribble(c("alfa", "alfa/bravo"))
#> # A dribble: 2 × 4
#>   name  path         id                                drive_resource   
#>   <chr> <chr>        <drv_id>                          <list>           
#> 1 alfa  ~/alfa/      1PpWsFCmIZG7eybIDS-s_c0rQmJcoQlbd <named list [33]>
#> 2 bravo ~/alfa/bravo 1zHMOzXdEVlW3GxvaKKzAXzI_XegJjdch <named list [39]>

# specify the file id (substitute a real file id of your own!)
# as_dribble(as_id("0B0Gh-SuuA2nTOGZVTXZTREgwZ2M"))

# Clean up
drive_find("alfa") %>% drive_rm()
#> File deleted:
#>alfa <id: 1PpWsFCmIZG7eybIDS-s_c0rQmJcoQlbd>