Write an object to file and upload file to SharePoint
Source:R/write_sharepoint.R
write_sharepoint.Rdwrite_sharepoint() uses upload_sp_item() to upload an object created
using:
sf::write_sf()if x is ansfobject (shapefiles are not supported)readr::write_csv()if x is adata.frameand file does not have a xlsx extensionopenxlsx2::write_xlsx()if x is adata.frameand file has a xlsx extensionThe
print()method from{officer}if x is ardocx,rpptx, orrxlsxobjectreadr::write_rds()if x is any other class
Usage
write_sharepoint(
x,
file,
dest = NULL,
...,
.f = NULL,
new_path = tempdir(),
overwrite = FALSE,
drive_name = NULL,
drive_id = NULL,
drive = NULL,
site_url = NULL,
site_name = NULL,
site_id = NULL,
site = NULL,
blocksize = 327680000,
call = caller_env()
)Arguments
- x
Object to write to file and upload to SharePoint.
sf,rdocx,rpptx,rxlsx, anddata.frameobjects are saved with the functions noted in the description. All other object types are saved asrdsoutputs.- file
File to write to. Passed to
fileparameter forreadr::write_csv()orreadr::write_rds(),dsnforsf::write_sf(), ortargetforprint()(when working with{officer}class objects). A shapefile writes more than one file, sofilecan't use a "shp" extension forsfobjects. Use a single file format like GeoPackage ("gpkg") or GeoJSON ("geojson") instead.- dest
Destination on SharePoint for file to upload. Must be a
ms_drive_itemfor a folder, a SharePoint folder URL, or a drive path. If ams_drive_itemis provided anddrive_nameisNULL, the item URL is used to determine the drive. IfNULL, the top level of the provided drive is used as the destination. If file is a directory,destmust be an existing directory. Ifdestis a SharePoint folder or document library URL anddrive_name,drive_id, anddrivearen't supplied, the drive and folder are found with the Microsoft Graph shares API (seeget_sp_item()). If the request fails, the drive and folder path are parsed from the URL instead. Forupload_sp_items(),destcan also be a character vector with one destination for each file. Destinations can be in different drives.- ...
Additional parameters passed to write function.
- .f
Optional function to write the input data to disk before uploading file to SharePoint.
- new_path
Path to write file to. Defaults to
tempdir()- overwrite
If
FALSE(default), error if an item with the name specified infileorsrcalready exists at the specified destination. IfTRUE, overwrite any existing items with the same name. The latter is the default for theupload_filemethod.- drive_name, drive_id
SharePoint drive name or ID.
- drive
A
ms_driveobject. 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_idmust be supplied.- site
A
ms_siteobject. Ifsiteis supplied,site_url,site_name, andsite_idare ignored.- blocksize
Additional parameter passed to
upload_folderorupload_filemethod forms_driveobjects.- call
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See thecallargument ofabort()for more information.