-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path06_dots_demo.Rmd
100 lines (70 loc) · 2.75 KB
/
06_dots_demo.Rmd
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: "passing queries in the dots!"
author: "Lucy D’Agostino McGowan"
date: "5/9/2017"
output:
github_document:
toc: true
---
*This is all about those dots[.](https://www.youtube.com/watch?v=GI6CfKcMhjY)*
Most of the functions have `...` which allow the user to input name-value pairs to query the API.
```{r, message = FALSE, warning = FALSE}
library('googledrive')
library('dplyr')
```
## List files
We list files using `drive_ls()`[.](https://www.youtube.com/watch?v=F-X4SLhorvw) Possible parameters to pass to the `...` can be found here. For example, by default files are listed in descending order by most recently modified.
Here is my list using the default:
```{r}
drive_ls()
```
Let's say I want to order them by folders, then modified time, then name. I can do that!
```{r}
drive_ls(orderBy = "folder,modifiedTime desc,name" )
```
As another example, by default, this will list 100 drive files. If we want to output more, we can pass the `pageSize` parameter[.](https://www.youtube.com/watch?v=cRpdIrq7Rbo&t=67s)
```{r}
drive_ls(pageSize = 200)
```
## Publish files
To publish files, we use `drive_publish()`. Parameters found [here](https://developers.google.com/drive/v3/reference/revisions/update) can be passed to the `...` of this function. For example, by default for Google Docs, subsequent revisions will be automatically republished. We can change this by passing the `publishAuto` parameter.
```{r}
my_file <- drive_get_id("test") %>%
drive_file %>%
drive_publish(publishAuto=FALSE)
```
```{r}
my_file$publish
```
## Share files
To share files, we use `drive_share()`. Parameters that can be passed to the `...` can be found [here](https://developers.google.com/drive/v3/reference/permissions/create). For example, if we set the `type` parameter as `anyone`, we can pass the `allowFileDiscovery` through the `...` to allow anyone to discover the file (this is equivalent to being "Public on the Web").
```{r}
my_file <- my_file %>%
drive_share(type = "anyone", role = "writer", allowFileDiscovery = TRUE)
```
```{r}
my_file$permissions
```
I also display this in the print method.
```{r}
my_file
```
## Uploading a file
To upload a file we use `drive_upload()`. Parameters that can be passed to the `...` can be found [here](https://developers.google.com/drive/v3/reference/files/update). For example, if you would like to add a file to a specific folder, and do not want to use the `drive_mv` function after, you can use `addParents`.
Let's grab a folder to stick the file in.
```{r}
folder <- drive_get_id("THIS IS A TEST") %>%
drive_file
```
Make sure it's a folder.
```{r}
folder
```
Upload to the folder.
```{r}
new_file <- drive_upload("demo.txt",addParents = folder$id)
```
## clean up
```{r}
new_file <- drive_delete(new_file)
```