Read a SharePoint item based on a file URL or file name and site details
Source:R/read_sharepoint.R
read_sharepoint.Rd
read_sharepoint()
is designed to download a SharePoint item to a temporary
folder and read the file based on the file extension. If a function is
provided to .f, it is used to read the downloaded file. If not, class of the
returned object depends on the file extension of the file parameter.
If the file is a csv, csv2, or tsv file or a Microsoft Excel file (xlsx or xls),
readr::read_delim()
orreadxl::read_excel()
is used to return a data frame.If the file is a rds file,
readr::read_rds()
is used to return the saved object.If the file is a pptx or docx file,
officer::read_docx()
orofficer::read_pptx()
are used to read the file into ardocx
orrpptx
object.If the file has a "gpkg", "geojson", "kml", "gdb", or "zip" file extension,
sf::read_sf()
is used to read the file into asf
data frame.
If the file has none of these file extensions, an attempt is made to read the
file with readr::read_lines()
.
Usage
read_sharepoint(
file,
...,
.f = NULL,
new_path = tempdir(),
overwrite = TRUE,
drive_name = NULL,
drive_id = NULL,
drive = NULL,
site_url = NULL,
site_name = NULL,
site_id = NULL,
site = NULL
)
Arguments
- file
Required. A SharePoint shared file URL, document URL, or, if
item_id
is supplied, a file name to use in combination withnew_path
to setdest
with location and filename for downloaded item.- ...
Additional parameters passed to one of the functions identified in the description or supplied to
.f
- .f
Optional function to use to read file downloaded from SharePoint.
- new_path
Path to directory for downloaded item. Optional if
dest
is supplied. If path contains a file name, the item will be downloaded using that file name instead of the file name of the original item. Ifnew_path
refers to a nonexistent directory and the item is a file, the directory will be silently created usingfs::dir_create()
.- overwrite
If
TRUE
, replace the existing cached object named bycache_file
with the new object. IfFALSE
, error if a cached file with the samecache_file
name already exists.- drive_name, drive_id
SharePoint drive name or ID.
- drive
A
ms_drive
object. If drive is supplied,drive_name
,site_url
, and any additional parameters passed to...
are ignored.- site_url
A SharePoint site URL in the format "https://[tenant name].sharepoint.com/sites/[site name]". Any SharePoint item or document URL can also be parsed to build a site URL using the tenant and site name included in the URL.
- site_name, site_id
Site name or ID of the SharePoint site as an alternative to the SharePoint site URL. Exactly one of
site_url
,site_name
, andsite_id
must be supplied.- site
A
ms_site
object. Ifsite
is supplied,site_url
,site_name
, andsite_id
are ignored.