library(Microsoft365R)
<- get_sharepoint_site("Workforce Programs")
wp <- wp$get_drive("Documents")
wp_docs
$list_files()
wp_docs
$download_file("path_to_file.xlsx") wp_docs
3 Sharepoint
Sharepoint is part of many data pipelines, and the easiest way to interact with Sharepoint from R is through the {Microsoft365R} package. This package has been vetted by the Department of Technology (DT) and authentication should be straight-forward after calling one of the initial functions.
It is helpful to wrap common read/write operations into more usable functions:
<- function(sp_site) {
connect_to_sharepoint_site_docs <- Microsoft365R::get_sharepoint_site(sp_site)
sp_site <- sp_site$get_drive("Documents")
sp_site_doc return(sp_site_doc)
}
<- function() connect_to_sharepoint_site_docs("Workforce Programs")
connect_to_wp_docs
<- function(sp_file, destination) {
download_from_wp <- connect_to_wp_docs()
docs $download_file(sp_file, dest = destination)
docs::cli_alert_success(glue::glue("{sp_file} downloaded."))
cli
}
<- function(file, sp_destination) {
upload_to_wp <- connect_to_wp_docs()
docs $upload_file(
docs
file,
sp_location
)::cli_alert_success(glue::glue("{file} uploaded."))
cli
}
<- function(path) {
read_wp <- tempfile(fileext = "xlsx")
tmp download_from_wp(
sp_file = glue("{path}.xlsx"),
destination = tmp
)<- readxl::read_excel(tmp, .name_repair = janitor::make_clean_names)
out return(out)
}