Skip to contents

A collection of helper functions for interacting with Microsoft 365 groups, including Teams, Planner, and SharePoint, via the AzureGraph package.

These functions simplify retrieval of group information, access to associated resources (Planner, SharePoint, Teams), and file transfer operations between local storage and SharePoint, including RDS import/export utilities.

Usage

get_ms365_group(group_name = "MMBI Unit Epidemiologie & Data Science")

get_planner(
  ms365_group = get_ms365_group(),
  plan_id = "xHLwHUqf_UKoTxaPT6gh5pYAHsuB"
)

get_sharepoint(ms365_group = get_ms365_group())

get_teams(ms365_group = get_ms365_group())

get_sharepoint_file(remote_path, ms365_group = get_ms365_group())

download_sharepoint_file(
  remote_path,
  destination,
  overwrite = FALSE,
  ms365_group = get_ms365_group()
)

upload_sharepoint_file(
  local_path,
  remote_path,
  ms365_group = get_ms365_group()
)

import_sharepoint_rds(remote_path, ms365_group = get_ms365_group())

export_sharepoint_rds(object, remote_path, ms365_group = get_ms365_group())

open_sharepoint_analysis_file(remote_path, ms365_group = get_ms365_group())

save_sharepoint_analysis_file(
  local_path = get_current_file_path(),
  remote_path = NULL,
  ms365_group = get_ms365_group()
)

get_current_file_path()

Arguments

group_name

Character scalar. Name of the Microsoft 365 group to connect to. Defaults to "MMBI Unit Epidemiologie & Data Science".

ms365_group

An az_group object obtained from get_ms365_group(). Defaults to calling get_ms365_group() automatically.

plan_id

Identifier of the Planner.

remote_path

Character scalar. Path to a file or folder on SharePoint (relative to the group drive root). For save_sharepoint_analysis_file() this will at default be taken from the first file line.

destination

Character scalar. Local path where a SharePoint file should be downloaded.

overwrite

Logical. Whether to overwrite an existing local or remote file. Default is FALSE.

local_path

Character scalar. Path to a local file to upload to SharePoint.

object

An R object to be saved as an .rds file and uploaded to SharePoint.

Details

These functions use the AzureGraph package to authenticate and connect to Microsoft 365 resources within the umcgonline tenant. Authentication is attempted using an existing cached login; if unavailable, the user is prompted to log in interactively.

Examples

if (FALSE) { # \dontrun{


# Get from / Save to SharePoint ----------------------------------------

# Export data set to remote
mtcars |> export_sharepoint_rds("Projecten/Overig/mtcars.rds")

# Import data set from remote
df <- import_sharepoint_rds("Projecten/Overig/iris.rds")

# Open analysis file in RStudio from remote
open_sharepoint_analysis_file("Projecten/Overig/my_file.R")

# Save current analysis file to remote
save_sharepoint_analysis_file()
# or press the button in the Addins menu in RStudio


# Other Helper Functions -----------------------------------------------

# Download a file from SharePoint
download_sharepoint_file("Projecten/Overig/my_remote_file.csv", "my_local_file.csv")

# Upload a local file to SharePoint
upload_sharepoint_file("my_local_file.csv", "Projecten/Overig/my_remote_file.csv")

# Access Teams
teams <- get_teams()
# Send a message
teams$get_channel("General")$send_message("This is message from R")

# Access Planner
planner <- get_planner()
planner$list_tasks()
} # }