create_sp_drive() creates a document library on a SharePoint site and
returns the library's drive as a ms_drive object. A document library is a
SharePoint list created with the "documentLibrary" template, so this
function wraps create_sp_list(). Columns, views, and folders can be
supplied with a list definition (see read_sp_list_yaml()).
The library's list can be used with the list functions (e.g.
compare_sp_list() or sync_sp_list()) and the drive can be used with the
file and folder functions (e.g. sp_dir_create() or upload_sp_item()).
create_sp_drive() doesn't create a SharePoint Embedded container (a Graph
fileStorageContainer). Containers aren't part of a SharePoint site and can
only be created by an app that owns a registered container type.
Usage
create_sp_drive(
drive_name = NULL,
description = NULL,
...,
folders = NULL,
definition = NULL,
properties = FALSE,
site_url = NULL,
site = NULL,
call = caller_env()
)Arguments
- drive_name
Library name used as the
displayNameproperty. SharePoint sets the library URL from this name, so the drive name and URL can't be changed separately. Required unlessdefinitionis supplied.- description
Optional description.
- ...
Additional parameters passed to
create_sp_list()(e.g.columns,content_types, orhidden) and toget_sp_site()ifsiteisNULL.- folders
Optional. A character vector of folder paths to create, relative to the library root (e.g.
c("Reports/2026", "Data")). Parent folders are created as needed. Replaces anyfoldersindefinition.- definition
Optional. A list definition from
read_sp_list_yaml()or a path to a YAML file. The definitionlist.templatemust bedocumentLibraryif it is set. Seecreate_sp_list()for how the definition is used.- properties
If
TRUE, return the drive properties instead of thems_driveobject. Defaults toFALSE.- 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
A
ms_siteobject. Ifsiteis supplied,site_url,site_name, andsite_idare ignored.- 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.
Value
A ms_drive object for the new library, or the drive properties
as a named list if properties = TRUE.
Examples
if (FALSE) { # \dontrun{
create_sp_drive(
"Project Files",
folders = c("Contracts", "Reports/2026"),
site_url = "<SharePoint site url>"
)
create_sp_drive(
definition = "library-fields/project-files.yaml",
site_url = "<SharePoint site url>"
)
} # }