if (FALSE) {
# personal OneDrive
mydrv <- get_personal_onedrive()
# OneDrive for Business
busdrv <- get_business_onedrive("mycompany")
# shared document library for a SharePoint site
site <- get_sharepoint_site("My site")
drv <- site$get_drive()
## file/folder operationss
drv$list_files()
drv$list_files("path/to/folder", full_names=TRUE)
# download a file -- default destination filename is taken from the source
drv$download_file("path/to/folder/data.csv")
# shareable links
drv$create_share_link("myfile")
drv$create_share_link("myfile", type="edit", expiry="24 hours")
drv$create_share_link("myfile", password="Use-strong-passwords!")
# file metadata (name, date created, etc)
drv$get_item_properties("myfile")
# rename a file -- item ID remains the same, while name is changed
obj <- drv$get_item("myfile")
drv$set_item_properties("myfile", name="newname")
# retrieve the renamed object by ID
id <- obj$properties$id
obj2 <- drv$get_item(itemid=id)
obj$properties$id == obj2$properties$id # TRUE
# saving and loading data
drv$save_dataframe(iris, "path/to/iris.csv")
iris2 <- drv$load_dataframe("path/to/iris.csv")
identical(iris, iris2) # TRUE
drv$save_rds(iris, "path/to/iris.rds")
iris3 <- drv$load_rds("path/to/iris.rds")
identical(iris, iris3) # TRUE
# accessing shared files
shared_df <- drv$list_shared_items()
shared_df$remoteItem[[1]]$open()
shared_items <- drv$list_shared_items(info="items")
shared_items[[1]]$open()
}
Run the code above in your browser using DataLab