Package 'defenestrate'

Title: Helpers for Working with Microsoft's Online Services Programmatically
Description: Some functions to simplify the process of working with files on Microsoft's online teamworking products (OneDrive, Teams). Built largely around the 'Microsoft365R' package.
Authors: Matt Dray [aut, cre]
Maintainer: Matt Dray <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-10-16 04:31:58 UTC
Source: https://github.com/matt-dray/defenestrate

Help Index


Check for a Specified Token

Description

Check for a Specified Token

Usage

.check_auth(scope_group = c("teams", "business_onedrive"))

Arguments

scope_group

Character. The name for a set of scopes that allow access to Microsoft services. See details.

Details

Each Microsoft product requires a token that covers particular scopes of interaction. The names of these, as used in the scope_group argument, are analogous to the associated functions in 'Microsoft365R': "team" for using Teams, the token for which is generated when you use Microsoft365R::list_teams; "business_onedrive" for using OneDrive, the token for which is generated when you use Microsoft365R::get_business_onedrive.

Value

Nothing if the specified token is found, otherwise an error.


Check for Internet

Description

Check for Internet

Usage

.check_internet()

Value

Nothing if there's an internet connection, otherwise a warning.


Identify File Type and Check that It's Valid

Description

Identify File Type and Check that It's Valid

Usage

.extract_file_type(filepath)

Arguments

filepath

Character. The path to a file that contains tabular data to be read in.

Value

A character string representing the filetype.


Choose a Function to Read a Given File Type and Read It

Description

Choose a Function to Read a Given File Type and Read It

Usage

.read_file_type(file_type, temp_file, ...)

Arguments

file_type

Character. The file extension of the file being read.

temp_file

Character. A filepath to a temporary file where the data will be written.

...

Additional arguments to pass to the function that will be used to read in the data, which depends on the type of file being read.

Value

A data.frame/tibble if the file exists and can be read.


List Available Files in a Business OneDrive Directory

Description

A shortcut for listing files in a directory in a business OneDrive that you have access to and have been authorised against (see details) without needing to interact with the R6 object returned by Microsoft365R::get_business_onedrive.

Usage

list_onedrive_files(filepath = NULL)

Arguments

filepath

Character. The path to a OneDrive directory starting from the root of your business OneDrive directory. Defaults to NULL, which will return the directories and files available to you from the root.

Details

You must have completed the authorisation process for the channel that you want to read from. To do this, run Microsoft365R::get_business_onedrive(), which will open the browser for automatic authorisation. A token authorising you for the required scopes will be stored on your computer.

Note that you'll see the message 'Loading Microsoft Graph login for default tenant' when tokens are being checked. You may also see 'Access token has expired or is no longer valid; refreshing' when your token is stale. Use base::suppressMessages to hide these messages.

Value

Character. The names of directories (suffixed with a forward slash) and files (suffixed with a file extension) available from the provided filepath.

Examples

## Not run: list_onedrive_files("Personal")

List Available Channels in a Teams Team

Description

A shortcut for listing channels in a Teams team that you have access to and have been authorised against (see details) without needing to interact with the R6 object returned by Microsoft365R::get_team.

Usage

list_teams_channels(team)

Arguments

team

Character. The name of a Teams team.

Details

You must have completed the authorisation process for Teams. To do this, run Microsoft365R::list_teams(), which will open the browser for automatic authorisation. A token authorising you for the required scopes will be stored on your computer.

Note that you'll see the message 'Loading Microsoft Graph login for default tenant' when tokens are being checked. You may also see 'Access token has expired or is no longer valid; refreshing' when your token is stale. Use base::suppressMessages to hide these messages.

Value

Character. Names of Teams channels available to you.

Examples

## Not run: list_teams_channels("Statistics Production Division"))

List Available Teams

Description

A shortcut for listing Teams teams that you have access to and have been authorised against (see details) without needing to interact with the R6 object returned by Microsoft365R::get_team.

Usage

list_teams_teams()

Details

You must have completed the authorisation process for Teams. To do this, run Microsoft365R::list_teams(), which will open the browser for automatic authorisation. A token authorising you for the required scopes will be stored on your computer.

Note that you'll see the message 'Loading Microsoft Graph login for default tenant' when tokens are being checked. You may also see 'Access token has expired or is no longer valid; refreshing' when your token is stale. Use base::suppressMessages to hide these messages.

Value

Character. Names of Teams teams available to you.

Examples

## Not run: list_teams_teams()

Read Tabular Data from a Teams Channel

Description

Read in data from a file that's available from a channel in a Microsoft Teams team that you have access to and have been authorised against (see details).

Usage

read_channel_table(team, channel, filepath, ...)

Arguments

team

Character. The name of a Teams team.

channel

Character. The name of a channel in the Teams team provided to the 'team' argument.

filepath

Character. The path to a file that contains tabular data to be read in.

...

Additional arguments to pass to the function that will be used to read in the data, which depends on the type of file being read. See details.

Details

You need to have a token on your computer that authorises you to use the scopes required to access data on Teams. The easiest way to do this is to run a function like Microsoft365R::list_teams, which will open a browser window and authorise you automatically. Then you can use 'defenestrate' functions. You only need to do this authorisation once.

Note that you'll see the message 'Loading Microsoft Graph login for default tenant' when tokens are being checked. You may also see 'Access token has expired or is no longer valid; refreshing' when your token is stale. Use base::suppressMessages to hide these messages.

The exact function used internally by read_channel_table to read data depends on the filetype. For Excel files, readxl::read_excel; for ODS files, readODS::read_ods; for CSV and TSV files, readr::read_csv and readr::read_tsv; for RDS files, readr::read_rds. You can supply extra arguments from these functions to the '...' (dots) argument. For example, if reading an xlsx file, you could use the argument sheet = 1 to read the first sheet only.

Value

A data.frame/tibble class object.

Examples

## Not run: read_channel_table("Team Name", "Channel Name", "file.csv")

Read Tabular Data from OneDrive

Description

Read in data from a file that's available from your business's OneDrive, which you have access to and have been authorised against (see details).

Usage

read_onedrive_table(filepath, ...)

Arguments

filepath

Character. The path to a file that contains tabular data to be read in, starting from the root of your Business OneDrive folder, i.e. C:/Users/your.name/OneDrive - UK Health Security Agency/ (see the files and folders available from this location by running list_onedrive_files with empty arguments).

...

Additional arguments to pass to the function that will be used to read in the data, which depends on the type of file being read. See details.

Details

You need to have a token on your computer that authorises you to use the scopes required to access data on Teams. The easiest way to do this is to run a function like Microsoft365R::get_business_onedrive, which will open a browser window and authorise you automatically. Then you can use defenestrate functions. You only need to do this authorisation once.

Note that you'll see the message 'Loading Microsoft Graph login for default tenant' when tokens are being checked. You may also see 'Access token has expired or is no longer valid; refreshing' when your token is stale. Use base::suppressMessages to hide these messages.

The exact function used internally by read_onedrive_table to read data depends on the filetype. For Excel files, readxl::read_excel; for ODS files, readODS::read_ods; for CSV and TSV files, readr::read_csv and readr::read_tsv; for RDS files, readr::read_rds. You can supply extra arguments from these functions to the '...' (dots) argument. For example, if reading an xlsx file, you could use the argument sheet = 1 to read the first sheet only.

Value

A data.frame/tibble class object.

Examples

## Not run: read_onedrive_table("Personal/file.csv")