diff --git a/_pkgdown.yml b/_pkgdown.yml index 9f242a245..005680a91 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -18,11 +18,17 @@ navbar: href: articles/index.html - text: File Identification href: articles/articles/file-identification.html + - text: Dealing with multiple files + href: articles/articles/multiple-files.html + - text: File permissions + href: articles/articles/permissions.html articles: - title: "Articles" contents: - file-identification + - multiple-files + - permissions reference: - title: "Reach out and touch your files" diff --git a/docs/LICENSE.html b/docs/LICENSE.html index cca08de3e..80e68805f 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/articles/articles/file-identification.html b/docs/articles/articles/file-identification.html index e6ca59d31..2020e372a 100644 --- a/docs/articles/articles/file-identification.html +++ b/docs/articles/articles/file-identification.html @@ -48,6 +48,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/articles/articles/multiple-files.html b/docs/articles/articles/multiple-files.html new file mode 100644 index 000000000..29c1070b4 --- /dev/null +++ b/docs/articles/articles/multiple-files.html @@ -0,0 +1,256 @@ + + + + + + + +Dealing with multiple files • googledrive + + + + + + +
    +
    + + + +
    +
    + + + + +
    +

    Some googledrive functions are built to naturally handle multiple files, while others operate on a single file.

    +

    Functions that expect a single file:

    + +

    Functions that allow multiple files:

    + +

    In general, the principle is: if there are multiple parameters that are likely to vary across multiple files, the function is designed to take a single input. In order to use these function with multiple inputs, use them together with your favorite approach for iteration in R. Below is a worked example, focusing on tools in the tidyverse, namely the map() functions in purrr.

    +
    +

    +Upload multiple files, then rename them

    +

    Scenario: we have multiple local files we want to upload into a folder on Drive. Then we regret their original names and want to rename them.

    +

    Load packages.

    +
    library(googledrive)
    +library(glue)
    +library(tidyverse)
    +#> + ggplot2 2.2.1        Date: 2017-08-27
    +#> + tibble  1.3.4           R: 3.3.2
    +#> + tidyr   0.6.3          OS: OS X El Capitan 10.11.6
    +#> + readr   1.1.1         GUI: X11
    +#> + purrr   0.2.3      Locale: en_CA.UTF-8
    +#> + dplyr   0.7.2          TZ: America/Vancouver
    +#> + stringr 1.2.0      
    +#> + forcats 0.2.0
    +#> Conflicts -----------------------------------------------------------------
    +#> * collapse(),  from dplyr, masks glue::collapse()
    +#> * filter(),    from dplyr, masks stats::filter()
    +#> * lag(),       from dplyr, masks stats::lag()
    +
    +

    +Upload

    +

    Use the example files that ship with googledrive. This looks a bit odd, but the first call returns their names and the second returns full paths on the local system.

    +
    local_files <- drive_example() %>% 
    +  drive_example()
    +

    Create a folder on your Drive and upload all files into this folder by iterating over the local_files using purrr::map().

    +
    folder <- drive_mkdir("upload-into-me-article-demo")
    +#> Auto-refreshing stale OAuth token.
    +#> Folder created:
    +#>   * upload-into-me-article-demo
    +files <- map(local_files, drive_upload, path = folder, verbose = FALSE)
    +

    files is now a list of dribbles, one per uploaded file. Let’s confirm that we uploaded the file into the new folder.

    +
    str(files, max.level = 1)
    +#> List of 4
    +#>  $ :Classes 'dribble', 'tbl_df', 'tbl' and 'data.frame': 1 obs. of  3 variables:
    +#>  $ :Classes 'dribble', 'tbl_df', 'tbl' and 'data.frame': 1 obs. of  3 variables:
    +#>  $ :Classes 'dribble', 'tbl_df', 'tbl' and 'data.frame': 1 obs. of  3 variables:
    +#>  $ :Classes 'dribble', 'tbl_df', 'tbl' and 'data.frame': 1 obs. of  3 variables:
    +drive_ls(folder)
    +#> # A tibble: 4 x 3
    +#>          name                           id drive_resource
    +#> *       <chr>                        <chr>         <list>
    +#> 1 chicken.txt 0B0Gh-SuuA2nTR1g4UmFvRXg2aE0    <list [36]>
    +#> 2 chicken.pdf 0B0Gh-SuuA2nTV0ZUQ1ByT2lJTVU    <list [36]>
    +#> 3 chicken.jpg 0B0Gh-SuuA2nTZzF0N2VuNlViVzg    <list [38]>
    +#> 4 chicken.csv 0B0Gh-SuuA2nTalRLdmlNRlJfVGM    <list [36]>
    +
    +
    +

    +Rename

    +

    Imagine that we now wish these file names had a date prefix. First, form the new names. We use glue::glue() for string interpolation but you could also use paste(). Second, we map over two inputs: the list of dribbles from above and the vector of new names.

    +
    new_names <- glue("{Sys.Date()}_{basename(local_files)}")
    +files_dribble <- map2_df(files, new_names, drive_rename)
    +#> File renamed:
    +#>   * chicken.csv -> 2017-08-27_chicken.csv
    +#> File renamed:
    +#>   * chicken.jpg -> 2017-08-27_chicken.jpg
    +#> File renamed:
    +#>   * chicken.pdf -> 2017-08-27_chicken.pdf
    +#> File renamed:
    +#>   * chicken.txt -> 2017-08-27_chicken.txt
    +## alternative: do this to get a list of dribbles for more downstream mapping
    +# files_list <- map2(files, new_names, drive_rename)
    +

    We use purrr::map2_df() to work through the list of dribbles (= Drive files) and the vector of new names and row bind the returned dribbles into a single dribble holding all files. In commented out code, we show an alternative using purrr::map2() that would return another list of dribbles. This would set you up better for downstream operations that required more map()ing.

    +

    Let’s check on the contents of this folder again:

    +
    drive_ls(folder)
    +#> # A tibble: 4 x 3
    +#>                     name                           id drive_resource
    +#> *                  <chr>                        <chr>         <list>
    +#> 1 2017-08-27_chicken.txt 0B0Gh-SuuA2nTR1g4UmFvRXg2aE0    <list [37]>
    +#> 2 2017-08-27_chicken.pdf 0B0Gh-SuuA2nTV0ZUQ1ByT2lJTVU    <list [37]>
    +#> 3 2017-08-27_chicken.jpg 0B0Gh-SuuA2nTZzF0N2VuNlViVzg    <list [38]>
    +#> 4 2017-08-27_chicken.csv 0B0Gh-SuuA2nTalRLdmlNRlJfVGM    <list [36]>
    +

    Note that you can always row bind individual dribbles into one big dribble yourself. We demo that with dplyr::bind_rows():

    +
    bind_rows(files)
    +#> # A tibble: 4 x 3
    +#>          name                           id drive_resource
    +#>         <chr>                        <chr>         <list>
    +#> 1 chicken.csv 0B0Gh-SuuA2nTalRLdmlNRlJfVGM    <list [36]>
    +#> 2 chicken.jpg 0B0Gh-SuuA2nTZzF0N2VuNlViVzg    <list [38]>
    +#> 3 chicken.pdf 0B0Gh-SuuA2nTV0ZUQ1ByT2lJTVU    <list [36]>
    +#> 4 chicken.txt 0B0Gh-SuuA2nTR1g4UmFvRXg2aE0    <list [36]>
    +
    +
    +

    +Clean up

    +

    Our trashing function, drive_trash() is vectorized and can therefore operate on a multi-file dribble. We could trash these files like so:

    +
    drive_trash(files_dribble)
    +

    If you’re absolutely sure of yourself and happy to do something irreversible, you could truly delete these files with drive_rm(), which is also vectorized:

    +
    drive_rm(files_dribble)
    +

    Finally – and this is the code we will actually execute – the easiest way to delete these files is to delete their enclosing folder.

    +
    drive_rm(folder)
    +#> Files deleted:
    +#>   * upload-into-me-article-demo: 0B0Gh-SuuA2nTQ3lUSm42OVBsdUE
    +
    +
    +
    +
    + + + +
    + + +
    +

    googledrive is a part of the tidyverse, an ecosystem of packages designed with common APIs and a shared philosophy. Learn more at tidyverse.org.

    +
    + +
    +

    Developed by Lucy D'Agostino McGowan, Jennifer Bryan, .

    +

    Site built by pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/articles/articles/permissions.html b/docs/articles/articles/permissions.html new file mode 100644 index 000000000..35bceb0be --- /dev/null +++ b/docs/articles/articles/permissions.html @@ -0,0 +1,207 @@ + + + + + + + +File permissions • googledrive + + + + + + +
    +
    + + + +
    +
    + + + + +
    +

    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-SuuA2nTaWhkdEpBVFl3TEE
    +#> with MIME type:
    +#>   * text/plain
    +file
    +#> # A tibble: 1 x 5
    +#>                       name shared                           id
    +#>                      <chr>  <lgl>                        <chr>
    +#> 1 chicken-perm-article.txt  FALSE 0B0Gh-SuuA2nTaWhkdEpBVFl3TEE
    +#> # ... 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-SuuA2nTaWhkdEpBVFl3TEE
    +#> # A tibble: 1 x 5
    +#>                       name shared                           id
    +#>                      <chr>  <lgl>                        <chr>
    +#> 1 chicken-perm-article.txt   TRUE 0B0Gh-SuuA2nTaWhkdEpBVFl3TEE
    +#> # ... 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-SuuA2nTaWhkdEpBVFl3TEE
    +

    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-08-27
    +#> + tibble  1.3.4           R: 3.3.2
    +#> + tidyr   0.6.3          OS: OS X El Capitan 10.11.6
    +#> + readr   1.1.1         GUI: X11
    +#> + purrr   0.2.3      Locale: en_CA.UTF-8
    +#> + dplyr   0.7.2          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-SuuA2nTaWhkdEpBVFl3TEE
    +
    +
    +
    + + + +
    + + + +
    + + + diff --git a/docs/articles/googledrive.html b/docs/articles/googledrive.html index 90610e346..e497d6ca4 100644 --- a/docs/articles/googledrive.html +++ b/docs/articles/googledrive.html @@ -48,6 +48,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/articles/index.html b/docs/articles/index.html index 3ef765301..f31e75626 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -84,7 +90,7 @@
    @@ -95,6 +101,8 @@

    Articles

    diff --git a/docs/authors.html b/docs/authors.html index 3f4bd714b..e52c6231c 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/index.html b/docs/index.html index 1fb2f6696..e803b73d6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -48,6 +48,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -182,17 +188,17 @@

    #> Local file: #> * /Users/jenny/resources/R/library/googledrive/extdata/chicken.csv #> uploaded into Drive file: -#> * README-chicken.csv: 0B0Gh-SuuA2nTdEtweWJvaTB4Yzg +#> * README-chicken.csv: 0B0Gh-SuuA2nTSDRScVhUbWlEaTA #> with MIME type: #> * text/csv #> # A tibble: 1 x 3 #> name id drive_resource #> * <chr> <chr> <list> -#> 1 README-chicken.csv 0B0Gh-SuuA2nTdEtweWJvaTB4Yzg <list [36]> +#> 1 README-chicken.csv 0B0Gh-SuuA2nTSDRScVhUbWlEaTA <list [36]>

    Notice that file was uploaded as text/csv. Since this was a .csv document, and we didn’t specify the type, googledrive guessed the MIME type. We can overrule this by using the type parameter to upload as a Google Spreadsheet. Let’s delete this file first.

    drive_rm(chicken)
     #> Files deleted:
    -#>   * README-chicken.csv: 0B0Gh-SuuA2nTdEtweWJvaTB4Yzg
    +#>   * README-chicken.csv: 0B0Gh-SuuA2nTSDRScVhUbWlEaTA
     
     ## example of using a dribble as input
     chicken_sheet <- drive_upload(
    @@ -203,7 +209,7 @@ 

    #> Local file: #> * /Users/jenny/resources/R/library/googledrive/extdata/chicken.csv #> uploaded into Drive file: -#> * README-chicken.csv: 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo +#> * README-chicken.csv: 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY #> with MIME type: #> * application/vnd.google-apps.spreadsheet

    Much better!

    @@ -217,7 +223,7 @@

    #> # A tibble: 1 x 5 #> name shared id #> <chr> <lgl> <chr> -#> 1 README-chicken.csv FALSE 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo +#> 1 README-chicken.csv FALSE 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY #> # ... with 2 more variables: drive_resource <list>, #> # permissions_resource <list>

    Here’s how to grant anyone with the link permission to be able to view this dataset.

    @@ -227,11 +233,11 @@

    #> * role = reader #> * type = anyone #> For files: -#> * README-chicken.csv: 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo +#> * README-chicken.csv: 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY #> # A tibble: 1 x 5 #> name shared id #> <chr> <lgl> <chr> -#> 1 README-chicken.csv TRUE 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo +#> 1 README-chicken.csv TRUE 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY #> # ... with 2 more variables: drive_resource <list>, #> # permissions_resource <list> @@ -250,7 +256,7 @@

    By default, drive_publish() will publish your most recent version.

    (chicken_sheet <- drive_publish(chicken_sheet))
     #> Files now published:
    -#>   * README-chicken.csv: 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo
    +#>   * README-chicken.csv: 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY
     #> # A tibble: 1 x 7
     #>                 name published shared
     #>                <chr>     <lgl>  <lgl>
    @@ -297,7 +303,7 @@ 
    #> Local file: #> * /Users/jenny/resources/R/library/googledrive/extdata/chicken.txt #> uploaded into Drive file: -#> * text-file.txt: 0B0Gh-SuuA2nTUHI4bGxQb1JHVGc +#> * text-file.txt: 0B0Gh-SuuA2nTbmdKUGUybGlJa28 #> with MIME type: #> * text/plain @@ -321,8 +327,8 @@

    Clean up

    drive_rm(chicken_sheet, text_file)
     #> Files deleted:
    -#>   * README-chicken.csv: 1IlgEdwAC47WyRmQbQTovGPPfQDnIbmyekNuSQNexfxo
    -#>   * text-file.txt: 0B0Gh-SuuA2nTUHI4bGxQb1JHVGc
    +#> * README-chicken.csv: 1zDxruu6Wz98SpZU2MjI5kGSDidb-NWwnvpcJIFFpHpY +#> * text-file.txt: 0B0Gh-SuuA2nTbmdKUGUybGlJa28
    diff --git a/docs/news/index.html b/docs/news/index.html index 236728b60..6b1339a70 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/as_dribble.html b/docs/reference/as_dribble.html index 585a5e292..17aee500b 100644 --- a/docs/reference/as_dribble.html +++ b/docs/reference/as_dribble.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/as_id.html b/docs/reference/as_id.html index 1f3d315d7..a9fccd5d8 100644 --- a/docs/reference/as_id.html +++ b/docs/reference/as_id.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/as_team_drive.html b/docs/reference/as_team_drive.html index f2881c112..6f15e2e28 100644 --- a/docs/reference/as_team_drive.html +++ b/docs/reference/as_team_drive.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/dribble-checks.html b/docs/reference/dribble-checks.html index 521d3ba28..efd54711e 100644 --- a/docs/reference/dribble-checks.html +++ b/docs/reference/dribble-checks.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/dribble.html b/docs/reference/dribble.html index 1e208b824..cd025be52 100644 --- a/docs/reference/dribble.html +++ b/docs/reference/dribble.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_about.html b/docs/reference/drive_about.html index 6672cc7e7..93557dcf5 100644 --- a/docs/reference/drive_about.html +++ b/docs/reference/drive_about.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_api_key.html b/docs/reference/drive_api_key.html index dd0065455..ec37c7ef0 100644 --- a/docs/reference/drive_api_key.html +++ b/docs/reference/drive_api_key.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -91,7 +97,7 @@

    Retrieve API key

    Retrieves the pre-configured API key. Learn more in Google's document -Credentials, access, security, andidentity. +Credentials, access, security, and identity. By default, this API key is initialized to one that ships with googledrive. But the user can store their own key via drive_auth_config(), i.e. overwrite the default.

    diff --git a/docs/reference/drive_auth.html b/docs/reference/drive_auth.html index 935cf0c37..1df812bec 100644 --- a/docs/reference/drive_auth.html +++ b/docs/reference/drive_auth.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -108,7 +114,7 @@

    Ar oauth_token

    Optional; path to an .rds file with a previously stored -oauth token.

    +OAuth token.

    service_token @@ -156,7 +162,7 @@

    Details .httr-oauth

  • For even deeper control over auth, use drive_auth_config() to use your own -oauth app or API key. drive_auth_config() also allows you to +OAuth app or API key. drive_auth_config() also allows you to deactivate auth, sending only an API key in requests, which works if you only need to access public data.

    diff --git a/docs/reference/drive_auth_config.html b/docs/reference/drive_auth_config.html index ba7a679e3..fcb36920c 100644 --- a/docs/reference/drive_auth_config.html +++ b/docs/reference/drive_auth_config.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -95,7 +101,7 @@

    View or set auth config

    gives control of:

  • diff --git a/docs/reference/drive_cp.html b/docs/reference/drive_cp.html index c87ae81d1..b9a19a8f5 100644 --- a/docs/reference/drive_cp.html +++ b/docs/reference/drive_cp.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_deauth.html b/docs/reference/drive_deauth.html index a74594c10..8560f638d 100644 --- a/docs/reference/drive_deauth.html +++ b/docs/reference/drive_deauth.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_download.html b/docs/reference/drive_download.html index 5619858bb..e8fc5160b 100644 --- a/docs/reference/drive_download.html +++ b/docs/reference/drive_download.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_empty_trash.html b/docs/reference/drive_empty_trash.html index b5686762c..e22646af6 100644 --- a/docs/reference/drive_empty_trash.html +++ b/docs/reference/drive_empty_trash.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_endpoints.html b/docs/reference/drive_endpoints.html index f43c8fe37..921bc4f5d 100644 --- a/docs/reference/drive_endpoints.html +++ b/docs/reference/drive_endpoints.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_example.html b/docs/reference/drive_example.html index 300beef35..79e67b3f8 100644 --- a/docs/reference/drive_example.html +++ b/docs/reference/drive_example.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_extension.html b/docs/reference/drive_extension.html index ac4ed161c..d53386eea 100644 --- a/docs/reference/drive_extension.html +++ b/docs/reference/drive_extension.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_fields.html b/docs/reference/drive_fields.html index f87e77705..78e7c152f 100644 --- a/docs/reference/drive_fields.html +++ b/docs/reference/drive_fields.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_find.html b/docs/reference/drive_find.html index f8c5bba8e..10fdc6581 100644 --- a/docs/reference/drive_find.html +++ b/docs/reference/drive_find.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_get.html b/docs/reference/drive_get.html index 8c027b9f6..7521847a7 100644 --- a/docs/reference/drive_get.html +++ b/docs/reference/drive_get.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_link.html b/docs/reference/drive_link.html index 8cf083f3d..290814a14 100644 --- a/docs/reference/drive_link.html +++ b/docs/reference/drive_link.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_ls.html b/docs/reference/drive_ls.html index ceab66b55..8730167d7 100644 --- a/docs/reference/drive_ls.html +++ b/docs/reference/drive_ls.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_mime_type.html b/docs/reference/drive_mime_type.html index 1cd217ea1..3d855d256 100644 --- a/docs/reference/drive_mime_type.html +++ b/docs/reference/drive_mime_type.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -90,7 +96,7 @@

    Lookup MIME type

    -

    This is a helper to determinine which MIME type should be used +

    This is a helper to determine which MIME type should be used for a file. Three types of input are acceptable:

  • diff --git a/docs/reference/drive_publish.html b/docs/reference/drive_publish.html index 86e14ca61..6a41cce85 100644 --- a/docs/reference/drive_publish.html +++ b/docs/reference/drive_publish.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_rename.html b/docs/reference/drive_rename.html index f99b4e830..b9a1787cb 100644 --- a/docs/reference/drive_rename.html +++ b/docs/reference/drive_rename.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_reveal.html b/docs/reference/drive_reveal.html index 4d9a0603e..80e62186d 100644 --- a/docs/reference/drive_reveal.html +++ b/docs/reference/drive_reveal.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_rm.html b/docs/reference/drive_rm.html index 4780bdddf..e11b8f9ae 100644 --- a/docs/reference/drive_rm.html +++ b/docs/reference/drive_rm.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_share.html b/docs/reference/drive_share.html index 24fdd98ca..87fa3ce89 100644 --- a/docs/reference/drive_share.html +++ b/docs/reference/drive_share.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_token.html b/docs/reference/drive_token.html index dee6f48cc..5e178eede 100644 --- a/docs/reference/drive_token.html +++ b/docs/reference/drive_token.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_trash.html b/docs/reference/drive_trash.html index f3b7d434b..bb5830708 100644 --- a/docs/reference/drive_trash.html +++ b/docs/reference/drive_trash.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_update.html b/docs/reference/drive_update.html index 02cb8fda2..8a74fd2bb 100644 --- a/docs/reference/drive_update.html +++ b/docs/reference/drive_update.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_upload.html b/docs/reference/drive_upload.html index f6bddb7eb..351269f50 100644 --- a/docs/reference/drive_upload.html +++ b/docs/reference/drive_upload.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/drive_user.html b/docs/reference/drive_user.html index af72d9562..2f9960c28 100644 --- a/docs/reference/drive_user.html +++ b/docs/reference/drive_user.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/expose.html b/docs/reference/expose.html index dc1a1a18c..b5e52a113 100644 --- a/docs/reference/expose.html +++ b/docs/reference/expose.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/generate_request.html b/docs/reference/generate_request.html index 11b71fe6d..66e72af09 100644 --- a/docs/reference/generate_request.html +++ b/docs/reference/generate_request.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/googledrive.html b/docs/reference/googledrive.html index 5031c1a31..ebb3f8df1 100644 --- a/docs/reference/googledrive.html +++ b/docs/reference/googledrive.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/index.html b/docs/reference/index.html index dddf73664..b558c8827 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • @@ -88,7 +94,7 @@ diff --git a/docs/reference/is_legit_token.html b/docs/reference/is_legit_token.html index c44468278..e8c1c157b 100644 --- a/docs/reference/is_legit_token.html +++ b/docs/reference/is_legit_token.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/make_request.html b/docs/reference/make_request.html index b82ec72fa..9ecd67c08 100644 --- a/docs/reference/make_request.html +++ b/docs/reference/make_request.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 23ee9d96f..3c9f98fe2 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/process_response.html b/docs/reference/process_response.html index 3dc504f09..b0492c52f 100644 --- a/docs/reference/process_response.html +++ b/docs/reference/process_response.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drive_create.html b/docs/reference/team_drive_create.html index a84cc7ce4..31d3fb2d0 100644 --- a/docs/reference/team_drive_create.html +++ b/docs/reference/team_drive_create.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drive_find.html b/docs/reference/team_drive_find.html index 3591e675a..2ab8a084b 100644 --- a/docs/reference/team_drive_find.html +++ b/docs/reference/team_drive_find.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drive_get.html b/docs/reference/team_drive_get.html index fddb1ddcd..68d4ca812 100644 --- a/docs/reference/team_drive_get.html +++ b/docs/reference/team_drive_get.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drive_rm.html b/docs/reference/team_drive_rm.html index da97ffe92..afaf839e7 100644 --- a/docs/reference/team_drive_rm.html +++ b/docs/reference/team_drive_rm.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drive_update.html b/docs/reference/team_drive_update.html index 886863517..321859dda 100644 --- a/docs/reference/team_drive_update.html +++ b/docs/reference/team_drive_update.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/team_drives.html b/docs/reference/team_drives.html index a927ceeb6..7172b403c 100644 --- a/docs/reference/team_drives.html +++ b/docs/reference/team_drives.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/docs/reference/token_available.html b/docs/reference/token_available.html index 68aadaf46..ebd808a34 100644 --- a/docs/reference/token_available.html +++ b/docs/reference/token_available.html @@ -67,6 +67,12 @@
  • File Identification
  • +
  • + Dealing with multiple files +
  • +
  • + File permissions +
  • diff --git a/vignettes/articles/multiple-files.Rmd b/vignettes/articles/multiple-files.Rmd new file mode 100644 index 000000000..f26dd5449 --- /dev/null +++ b/vignettes/articles/multiple-files.Rmd @@ -0,0 +1,122 @@ +--- +title: "Dealing with multiple files" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Dealing with multiple files} + %\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) +``` + +Some googledrive functions are built to naturally handle multiple files, while others operate on a single file. + +Functions that expect a single file: + +* `drive_browse()` +* `drive_cp()` +* `drive_download()` +* `drive_ls()` +* `drive_mkdir()` +* `drive_mv()` +* `drive_rename()` +* `drive_update()` +* `drive_upload()` + +Functions that allow multiple files: + +* `drive_publish()` +* `drive_reveal()` +* `drive_rm()` +* `drive_share()` +* `drive_trash()` + +In general, the principle is: if there are multiple parameters that are likely to vary across multiple files, the function is designed to take a single input. In order to use these function with multiple inputs, use them together with your favorite approach for iteration in R. Below is a worked example, focusing on tools in the tidyverse, namely the `map()` functions in purrr. + +## Upload multiple files, then rename them + +Scenario: we have multiple local files we want to upload into a folder on Drive. Then we regret their original names and want to rename them. + +Load packages. + +```{r} +library(googledrive) +library(glue) +library(tidyverse) +``` + +### Upload + +Use the example files that ship with googledrive. This looks a bit odd, but the first call returns their names and the second returns full paths on the local system. + +```{r} +local_files <- drive_example() %>% + drive_example() +``` + +Create a folder on your Drive and upload all files into this folder by iterating over the `local_files` using `purrr::map()`. + +```{r} +folder <- drive_mkdir("upload-into-me-article-demo") +files <- map(local_files, drive_upload, path = folder, verbose = FALSE) +``` + +`files` is now a list of **dribbles**, one per uploaded file. Let's confirm that we uploaded the file into the new folder. + +```{r} +str(files, max.level = 1) +drive_ls(folder) +``` + +### Rename + +Imagine that we now wish these file names had a date prefix. First, form the new names. We use `glue::glue()` for string interpolation but you could also use `paste()`. Second, we map over two inputs: the list of dribbles from above and the vector of new names. + +```{r} +new_names <- glue("{Sys.Date()}_{basename(local_files)}") +files_dribble <- map2_df(files, new_names, drive_rename) +## alternative: do this to get a list of dribbles for more downstream mapping +# files_list <- map2(files, new_names, drive_rename) +``` + +We use `purrr::map2_df()` to work through the list of dribbles (= Drive files) and the vector of new names and row bind the returned dribbles into a single dribble holding all files. In commented out code, we show an alternative using `purrr::map2()` that would return another list of dribbles. This would set you up better for downstream operations that required more `map()`ing. + +Let's check on the contents of this folder again: + +```{r} +drive_ls(folder) +``` + +Note that you can always row bind individual dribbles into one big dribble yourself. We demo that with `dplyr::bind_rows()`: + +```{r} +bind_rows(files) +``` + +### Clean up + +Our trashing function, `drive_trash()` is vectorized and can therefore operate on a multi-file dribble. We could trash these files like so: + +```{r eval = FALSE} +drive_trash(files_dribble) +``` + +If you're absolutely sure of yourself and happy to do something irreversible, you could truly delete these files with `drive_rm()`, which is also vectorized: + +```{r eval = FALSE} +drive_rm(files_dribble) +``` + +Finally -- and this is the code we will actually execute -- the easiest way to delete these files is to delete their enclosing folder. + +```{r} +drive_rm(folder) +``` diff --git a/vignettes/articles/permissions.Rmd b/vignettes/articles/permissions.Rmd new file mode 100644 index 000000000..251bd8fba --- /dev/null +++ b/vignettes/articles/permissions.Rmd @@ -0,0 +1,86 @@ +--- +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", .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) +``` + +## Clean up + +```{r} +drive_rm(file) +``` + +