ms_drive: Personal OneDrive or SharePoint document library

Description Format Fields Methods Initialization File and folder operations See Also Examples

Description

Class representing a personal OneDrive or SharePoint document library.

Format

An R6 object of class ms_drive, inheriting from ms_object.

Fields

Methods

Initialization

Creating new objects of this class should be done via the get_drive methods of the ms_graph, az_user or ms_site classes. Calling the new() method for this class only constructs the R object; it does not call the Microsoft Graph API to retrieve or create the actual drive.

File and folder operations

This class exposes methods for carrying out common operations on files and folders.

list_items(path, info, full_names, pagesize) lists the items under the specified path. It is the analogue of base R's dir/list.files. Its arguments are

list_files is a synonym for list_items.

download_file and upload_file download and upload files from the local machine to the drive. For upload_file, the uploading is done in blocks of 32MB by default; you can change this by setting the blocksize argument. For technical reasons, the block size must be a multiple of 320KB.

create_folder creates a folder with the specified path. Trying to create an already existing folder is an error.

open_item opens the given file or folder in your browser.

create_share_link(path, type, expiry, password, scope) returns a shareable link to the item. Its arguments are

This function returns a URL to access the item, for type="view" or "type=edit". For type="embed", it returns a list with components webUrl containing the URL, and webHtml containing a HTML fragment to embed the link in an IFRAME. The default is a viewable link, expiring in 7 days.

delete_item deletes a file or folder. By default, it will ask for confirmation first.

get_item_properties returns an object of ms_drive_item, containing the properties (metadata) for a given file or folder. The properties can be found in the properties field of this object.

set_item_properties sets the properties (metadata) of a file or folder. The new properties should be specified as individual named arguments to the method. Any existing properties that aren't listed as arguments will retain their previous values or be recalculated based on changes to other properties, as appropriate.

See Also

personal_onedrive, business_onedrive, ms_site, ms_drive_item

Microsoft Graph overview, OneDrive API reference

Examples

 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
## Not run: 

# personal OneDrive
mydrv <- personal_onedrive()

# OneDrive for Business
busdrv <- business_onedrive("mycompany")

# shared document library for a SharePoint site
site <- sharepoint_site("https://mycompany.sharepoint.com/sites/my-site-name")
drv <- site$get_drive()

## file/folder operationss
drv$list_items()
drv$list_items("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!")

myfile <- drv$get_item_properties("myfile")
myfile$properties

# rename a file
drv$set_item_properties("myfile", name="newname")


## End(Not run)

hongooi73/Microsoft365R documentation built on Jan. 12, 2021, 12:36 a.m.