Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (70 sloc) 2.62 KB
---
title: "File permissions"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Dealing with permissions}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## use a token from our development account
token_path <- rprojroot::find_package_root_file("tidyverse-noncaching-token.rds")
googledrive::drive_auth(token_path)
```
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.
```{r}
library(googledrive)
file <- drive_example("chicken.txt") %>%
drive_upload(name = "chicken-perm-article.txt") %>%
drive_reveal("permissions")
file
```
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.
```{r, eval = FALSE}
file <- file %>%
drive_share(
role = "writer",
type = "user",
emailAddress = "serena@example.com",
emailMessage = "Would appreciate your feedback on this!"
)
file
```
```{r, echo = FALSE}
file <- file %>%
drive_share(
role = "writer",
type = "user",
emailAddress = "jenny@stat.ubc.ca",
emailMessage = "Would appreciate your feedback on this!"
)
file
```
We see that the file is now shared. We also want anyone to be able to read the file.
```{r}
file <- file %>%
drive_share(role = "reader", type = "anyone")
```
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](https://github.com/tidyverse/googledrive/issues/180)*). We use other packages in the tidyverse now for this data wrangling.
```{r}
library(tidyverse)
perm <- pluck(file, "permissions_resource", 1, "permissions")
permissions <- tibble(
id = map_chr(perm, "id", .default = NA_character_),
name = map_chr(perm, "displayName", .default = NA_character_),
type = map_chr(perm, "type", .default = NA_character_),
role = map_chr(perm, "role", .default = NA_character_),
email = map_chr(perm, "emailAddress", .default = NA_character_)
)
as.data.frame(permissions)
```
## Clean up
```{r}
drive_rm(file)
```