You can use googledrive to manage permissions on your Drive files, i.e. grant different people or groups of people various levels of access (read, comment, edit, etc.).

Let’s upload a file and view its permissions.

library(googledrive)
file <- drive_example("chicken.txt") %>%
  drive_upload(name = "chicken-perm-article.txt") %>% 
  drive_reveal("permissions")
#> Auto-refreshing stale OAuth token.
#> Local file:
#>   * /Users/jenny/resources/R/library/googledrive/extdata/chicken.txt
#> uploaded into Drive file:
#>   * chicken-perm-article.txt: 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8
#> with MIME type:
#>   * text/plain
file
#> # A tibble: 1 x 5
#>                       name shared                           id
#>                      <chr>  <lgl>                        <chr>
#> 1 chicken-perm-article.txt  FALSE 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8
#> # ... with 2 more variables: drive_resource <list>,
#> #   permissions_resource <list>

The shared column shows that this file is not yet shared with anyone and, for those so inclined, detailed information on permissions can be found in the permissions_resource list-column.

Let’s give a specific person permission to edit this file and a customized message, using the emailAddress and emailMessage parameters.

file <- file %>%
  drive_share(
    role = "writer",
    type = "user",
    emailAddress = "serena@example.com",
    emailMessage = "Would appreciate your feedback on this!"
  )
file
#> Permissions updated
#>   * role = writer
#>   * type = user
#> For files:
#>   * chicken-perm-article.txt: 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8
#> # A tibble: 1 x 5
#>                       name shared                           id
#>                      <chr>  <lgl>                        <chr>
#> 1 chicken-perm-article.txt   TRUE 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8
#> # ... with 2 more variables: drive_resource <list>,
#> #   permissions_resource <list>

We see that the file is now shared. We also want anyone to be able to read the file.

file <- file %>%
  drive_share(role = "reader", type = "anyone")
#> Permissions updated
#>   * role = reader
#>   * type = anyone
#> For files:
#>   * chicken-perm-article.txt: 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8

Now that we’ve made a few updates to our permissions, the permissions_resource list-column has become more interesting. Here’s how to pull important information out of this and put into a tibble with one row per permission. (Permission handling will become more formalized in future versions of googledrive. See the issue). We use other packages in the tidyverse now for this data wrangling.

library(tidyverse)
#> + ggplot2 2.2.1             Date: 2017-09-23
#> + tibble  1.3.4                R: 3.4.1
#> + tidyr   0.7.1               OS: macOS Sierra 10.12.6
#> + readr   1.1.1              GUI: X11
#> + purrr   0.2.3.9000      Locale: en_CA.UTF-8
#> + dplyr   0.7.3               TZ: America/Vancouver
#> + stringr 1.2.0           
#> + forcats 0.2.0
#> ── Conflicts ────────────────────────────────────────────────────
#> * filter(),  from dplyr, masks stats::filter()
#> * lag(),     from dplyr, masks stats::lag()
perm <- pluck(file, "permissions_resource", 1, "permissions")
permissions <- tibble(
  id = map_chr(perm, "id", .null = NA_character_),
  name = map_chr(perm, "displayName", .null = NA_character_),
  type = map_chr(perm, "type", .null = NA_character_),
  role = map_chr(perm, "role", .null = NA_character_),
  email = map_chr(perm, "emailAddress", .null = NA_character_)
)
as.data.frame(permissions)
#>                     id                name   type   role
#> 1 01555823402173812461 tidyverse testdrive   user  owner
#> 2 14650328737125225074      Jennifer Bryan   user writer
#> 3       anyoneWithLink                <NA> anyone reader
#>                           email
#> 1 tidyverse.testdrive@gmail.com
#> 2             jenny@stat.ubc.ca
#> 3                          <NA>

Clean up

drive_rm(file)
#> Files deleted:
#>   * chicken-perm-article.txt: 0B0Gh-SuuA2nTVEQwTS0yYWt1RG8