Title: | Sharepoint Connectivity |
---|---|
Description: | A series of functions that allow users to connect to Sharepoint within an R session via the Microsoft Graph API. |
Authors: | Healthcare Quality Intelligence Unit (Western Australia Health) [aut, cre] |
Maintainer: | Healthcare Quality Intelligence Unit (Western Australia Health) <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.1.0 |
Built: | 2025-04-02 11:16:30 UTC |
Source: | https://github.com/AUS-DOH-Safety-and-Quality/qiverse |
Download SharePoint File
download_sharepoint_file( site_url, file_url, token, download = FALSE, download_dest = NULL )
download_sharepoint_file( site_url, file_url, token, download = FALSE, download_dest = NULL )
site_url |
This is the url when first accessing the sharepoint team via your web browser (Home page) |
file_url |
This is a direct link to the file to be downloaded. It can be obtained by navigating to the file you want to download, right-clicking and selecting "Copy Link" |
token |
The token generated with the correct SharePoint permissions. Use get_az_tk('sp") to create this token. |
download |
Set this to FALSE to download the file into a temporary file. This temporary file can then be read in using any standard data reading function. Set this to TRUE to download the file to your computer. |
download_dest |
This option is only active when download is set to TRUE. When download_location is set to NULL, the file is just downloaded into the current working directory. Otherwise, specify the destination path to save the file. |
A temporary file stored in an object if download is set to FALSE. If download is set to TRUE, the selected file is downloaded to the chosen directory.
## Not run: # Create SharePoint azure token tk <- get_az_tk('sp') # Download file to working directory from SharePoint site download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = TRUE ) # Download file to C:/ drive from SharePoint subsite download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = TRUE, download_dest = 'C:/test.csv' ) # Example to download to tempfile, to load straight into R memory data <- download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = FALSE ) |> # Pipe in the appropriate function to read in the data read.csv() ## End(Not run)
## Not run: # Create SharePoint azure token tk <- get_az_tk('sp') # Download file to working directory from SharePoint site download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = TRUE ) # Download file to C:/ drive from SharePoint subsite download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = TRUE, download_dest = 'C:/test.csv' ) # Example to download to tempfile, to load straight into R memory data <- download_sharepoint_file( site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk, download = FALSE ) |> # Pipe in the appropriate function to read in the data read.csv() ## End(Not run)
Download SharePoint list
download_sharepoint_list(list_url, token)
download_sharepoint_list(list_url, token)
list_url |
The URL of the list when accessing the list via your web browser. |
token |
The token generated with the correct SharePoint permissions. Use get_az_tk('sp") to create this token. |
A data.table of the SharePoint list
## Not run: # Get the token for SharePoint tk <- get_az_tk('sp') # Download a particular view for the SharePoint list list_data <- download_sharepoint_list( paste0("https://myexample.sharepoint.com/sites/", "Field%20Metadata/Lists/Fields/", "Latest.aspx"), token = tk ) # Download the default view for the SharePoint list list_data <- download_sharepoint_list( paste0("https://myexample.sharepoint.com/sites/", "Field%20Metadata/Lists/Fields/"), token = tk ) ## End(Not run)
## Not run: # Get the token for SharePoint tk <- get_az_tk('sp') # Download a particular view for the SharePoint list list_data <- download_sharepoint_list( paste0("https://myexample.sharepoint.com/sites/", "Field%20Metadata/Lists/Fields/", "Latest.aspx"), token = tk ) # Download the default view for the SharePoint list list_data <- download_sharepoint_list( paste0("https://myexample.sharepoint.com/sites/", "Field%20Metadata/Lists/Fields/"), token = tk ) ## End(Not run)
Upload SharePoint File
upload_sharepoint_file(src, site_url, dest_fldr_url, token)
upload_sharepoint_file(src, site_url, dest_fldr_url, token)
src |
The file path to the local file that is being uploaded to SharePoint |
site_url |
This is the url when first accessing the sharepoint team via your web browser (Home page) |
dest_fldr_url |
This is a direct link to the SharePoint folder where the file will be uploaded to. It can be obtained by navigating to the folder you want to upload to, right-clicking and selecting "Copy Link" |
token |
The token generated with the correct SharePoint permissions. Use get_az_tk('sp") to create this token. |
Upload local file to selected SharePoint folder.
## Not run: # Create SharePoint azure token tk <- get_az_tk('sp') # Example to upload local file to SharePoint folder upload_sharepoint_file( src = 'TestFiles/test.txt', site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk ) ## End(Not run)
## Not run: # Create SharePoint azure token tk <- get_az_tk('sp') # Example to upload local file to SharePoint folder upload_sharepoint_file( src = 'TestFiles/test.txt', site_url = "https://myexample.sharepoint.com/sites/Example-Files/"), file_url = paste0("https://myexample.sharepoint.com/:x:/r/sites/Example-Files/Shared%20Documents/Example_datasets/example_data_amended.csv?d=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"), token = tk ) ## End(Not run)