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-11-15 04:36:33 UTC |
Source: | https://github.com/matt-dray/defenestrate |
Check for a Specified Token
.check_auth(scope_group = c("teams", "business_onedrive"))
.check_auth(scope_group = c("teams", "business_onedrive"))
scope_group |
Character. The name for a set of scopes that allow access to Microsoft services. See 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.
Nothing if the specified token is found, otherwise an error.
Check for Internet
.check_internet()
.check_internet()
Nothing if there's an internet connection, otherwise a warning.
Identify File Type and Check that It's Valid
.extract_file_type(filepath)
.extract_file_type(filepath)
filepath |
Character. The path to a file that contains tabular data to be read in. |
A character string representing the filetype.
Choose a Function to Read a Given File Type and Read It
.read_file_type(file_type, temp_file, ...)
.read_file_type(file_type, temp_file, ...)
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. |
A data.frame/tibble if the file exists and can be read.
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.
list_onedrive_files(filepath = NULL)
list_onedrive_files(filepath = NULL)
filepath |
Character. The path to a OneDrive directory starting from the
root of your business OneDrive directory. Defaults to |
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.
Character. The names of directories (suffixed with a forward slash) and files (suffixed with a file extension) available from the provided filepath.
## Not run: list_onedrive_files("Personal")
## Not run: list_onedrive_files("Personal")
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.
list_teams_channels(team)
list_teams_channels(team)
team |
Character. The name of a Teams team. |
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.
Character. Names of Teams channels available to you.
## Not run: list_teams_channels("Statistics Production Division"))
## Not run: list_teams_channels("Statistics Production Division"))
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.
list_teams_teams()
list_teams_teams()
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.
Character. Names of Teams teams available to you.
## Not run: list_teams_teams()
## Not run: list_teams_teams()
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).
read_channel_table(team, channel, filepath, ...)
read_channel_table(team, channel, filepath, ...)
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. |
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.
A data.frame/tibble class object.
## Not run: read_channel_table("Team Name", "Channel Name", "file.csv")
## Not run: read_channel_table("Team Name", "Channel Name", "file.csv")
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).
read_onedrive_table(filepath, ...)
read_onedrive_table(filepath, ...)
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. |
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.
A data.frame/tibble class object.
## Not run: read_onedrive_table("Personal/file.csv")
## Not run: read_onedrive_table("Personal/file.csv")