-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial_googledrive-pkg.qmd
45 lines (29 loc) · 2.96 KB
/
tutorial_googledrive-pkg.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
title: "Conecting R & Google Drive"
---
## Overview
The [`googledrive` R package](https://googledrive.tidyverse.org/) is a package that lets R users directly interact with files on GoogleDrive. This can be extremely useful because it lets all members of a team share the same source data file(s) and guarantees that updates to "living" documents are received by all group members the next time they run their R script. This package is technically part of the Tidyverse but is not loaded by running `library(tidyverse)`.
Because this package requires access to an R user's GoogleDrive, you must "authenticate" the `googledrive` package. This essentially tells Google that it is okay if an R package uses your credentials to access and (potentially) modify your Drive content. There are only a few steps to this process but follow along with the below tutorial and we'll get you ready to integrate the Google Drive into your code workflows using the `googledrive` package in no time!
### Prerequisites
To follow along with this tutorial you will need to take the following steps:
- Download [R](https://cran.r-project.org/)
- Download [RStudio](https://posit.co/downloads/)
- Create a Gmail account
Feel free to skip any steps that you have already completed!
### Authorize `googledrive`
{{< include /modules_tutorials/googledrive-auth.qmd >}}
### Problems with Authorization
If you have tried to use `drive_auth` and *did not* check the box indicated above, you need to make the `googledrive` package ask you again. Using `drive_auth` will not (annoyingly) return you to the place it sent you the first time. However, if you run the following code chunk it should give you another chance to check the needed box.
The [`gargle` R package](https://gargle.r-lib.org/) referenced below is required for interacting with Google Application Program Interfaces (APIs). This package does the heavy lifting of secure password and token management and is necessary for the `googledrive` authentication chunk below.
```{r re-auth, eval = F}
googledrive::drive_auth(
email = gargle::gargle_oauth_email(),
path = NULL,
scopes = "https://www.googleapis.com/auth/drive",
cache = gargle::gargle_oauth_cache(),
use_oob = gargle::gargle_oob_default(),
token = NULL)
```
Unfortunately, to use the `googledrive` package you *must* check the box that empowers the package to function as designed. If you're uncomfortable giving the `googledrive` that much power you will need to pivot your workflow away from using GoogleDrive directly. However, NCEAS does offer access to an [internal server called "Aurora"](https://lter.github.io/workshop-github/server.html) where data can be securely saved and shared among group members without special authentication like what `googledrive` requires. Reach out to our team if this seems like a more attractive option for your working group and we can offer training on how to use this powerful tool!
### Find and Download Files
{{< include /modules_tutorials/googledrive-fxns.qmd >}}