library("googledrive")
library("testthat")

Let's upload a file.

drive_auth("drive-token.rds")
x <- drive_upload(system.file("DESCRIPTION"), "test-upload-lucy")

Overwrite using a dribble

Let's try to upload a file into that same location, using the x dribble object. This won't work with drive_upload().

## this should error
y <- drive_upload(system.file("DESCRIPTION"), x)

Let's use drive_update(). Now this should work.

y <- drive_update(system.file("DESCRIPTION"), x)

The ids for x and y should be identical.

identical(y$id, x$id)

Overwrite using a character path

y <- drive_update(system.file("DESCRIPTION"), "test-upload-lucy")
identical(y$id, x$id)

If we use drive_upload(), it should still create the file. Now we will have 2 files in the same location with the same name.

y <- drive_upload(system.file("DESCRIPTION"), "test-upload-lucy")

Now the ids should no longer be identical.

!identical(x$id, y$id)
drive_find("test-upload-lucy")

If we try to overwrite again, we should receive an error, since we don't know which to overwrite.

z <- drive_update(system.file("DESCRIPTION"),
                  "test-upload-lucy")

Folders

Let's make sure this plays nice with folders

folder <- drive_mkdir("test-folder-lucy")
a <- drive_upload(system.file("DESCRIPTION"), folder, "test-upload-lucy")

Let's make sure a is actually in folder.

a_parent <- unlist(a$files_resource[[1]]$parents)
identical(a_parent, folder$id)
b <- drive_update(system.file("DESCRIPTION"), a)

b should also exist in folder.

b_parent <- unlist(b$files_resource[[1]]$parents)
identical(b_parent, folder$id)

If I try to stick it in a folder that does not exist, it should complain that the path is not on Drive. You will receive this error if you give any path but it does not exist on your Drive.

c <- drive_upload(system.file("DESCRIPTION"), "this is not a real folder", name = "new_name")

Note: if you want to update AND give it a new name, you have to use drive_rename().

clean up

drive_rm(c("test-upload-lucy", "test-folder-lucy"))


tidyverse/googledrive documentation built on Jan. 14, 2024, 3:44 a.m.