This is all about those dots.

Most of the functions have ... which allow the user to input name-value pairs to query the API.

library('googledrive')
library('dplyr')

List files

We list files using drive_ls(). 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:

drive_ls()

Let's say I want to order them by folders, then modified time, then name. I can do that!

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.

drive_ls(pageSize = 200)

Publish files

To publish files, we use drive_publish(). Parameters found here 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.

my_file <- drive_get_id("test") %>%
  drive_file %>%
  drive_publish(publishAuto=FALSE)
my_file$publish

Share files

To share files, we use drive_share(). Parameters that can be passed to the ... can be found here. 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").

my_file <- my_file %>%
  drive_share(type = "anyone", role = "writer", allowFileDiscovery = TRUE)
my_file$permissions

I also display this in the print method.

my_file

Uploading a file

To upload a file we use drive_upload(). Parameters that can be passed to the ... can be found here. 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.

folder <- drive_get_id("THIS IS A TEST") %>%
  drive_file

Make sure it's a folder.

folder

Upload to the folder.

new_file <- drive_upload("demo.txt",addParents = folder$id)

clean up

new_file <- drive_delete(new_file)


LucyMcGowan/googledrive documentation built on Jan. 14, 2024, 3:30 a.m.