Reading OneDrive and SharePoint files with read365 R package
R
read365
Author
Artur Quirino
Published
February 8, 2023
Modified
February 20, 2023
In this post, I would like to introduce four functions available in the read365 package that allow for the reading of OneDrive and SharePoint files: OneDrive_file, SharePoint_file, OneDrive_shared_file and SharePoint_shared_file. The former two functions are intended for private content, while the last two are designed for public files. It is worth noting that read365 is heavily reliant on the Microsoft365R package.
The goal of the read365 package is to allow users to read files from office365 directly in R, without the need to sync files between their computer and the cloud.
Reading private content from OneDrive
The OneDrive_file function executes the login process onto OneDrive by utilizing Azure Active Directory authentication. Upon successful authentication, OneDrive_file requires users to set three parameters: the location of the file (file), the desired function for reading the file (.function), and optionally, arguments for this function (...). See the example below.
Shortly, the usage of the SharePoint_file is similiar to OneDrive_file. However, there are two additional parameters that must be set: SharePoint and drive. In the SharePoint parameter, the user is required to specify the SharePoint URL where the target file is located. As SharePoint may contain multiple drives to store files, users must indicate the specific drive1 to be accessed too. In most cases, “Documents” is the primary drive for storing files in SharePoint.
Reading public content from OneDrive or SharePoint
To use OneDrive_shared_file or SharePoint_shared_file2 no authentication is required. Therefore, all that is needed is to provide the file’s URL along with the corresponding function for reading the file and, optionally, its respective parameters.