NOTE: If a function allows you to pass file connections, using a cloud_file will be a better option for uploading files to OneDrive or SharePoint. See ?cloud_file for details.

upload_cloud_file(x, writer, file, drive, ...)

upload_sharepoint_file(x, writer, file, ...)

upload_onedrive_file(x, writer, file, ...)

Arguments

x

Data object to be written

writer

A function used to the provided data to disk

file

Destination filepath appropriate for SharePoint or OneDrive

drive

ms_drive object properly connected to OneDrive or SharePoint

...

Additional parameters to pass to writer

Value

Nothing

Details

These functions handle the necessary process to take a file and place it on either SharePoint or OneDrive without leaving a local artifact. This is done by leveraging the automatically created OneDrive and SharePoint ms_drive objects stored within the m365filer package, but the user may provide their own ms_drive object by using upload_cloud_file.

This function works by taking a writer object as a function. For example, if you want to upload a CSV file to SharePoint, you would provide the data you'd like to write, then write.csv into the writer parameter. Note you must pass the function object itself by not passing in the parentheses. This function then uses the writer to write out a temporary file, uploads that file to SharePoint or OneDrive at the path specified in the file parameter, and then cleans up after itself.

Note that this function makes a weak assumption about the syntax of the writer function. It's assumed that the first parameter will be the object write, and the second object will be the file path for which the file should be written. This is convention of most writer functions in R, like write_csv, write.csv, writexl::write_xlsx, and more, but it's not guaranteed.

For information about how the file path should be specified to properly assign the destination of your file, see ?ms365_help.

Examples

if (FALSE) {
mtcars %>%
  upload_cloud_file(
    write.csv,
    "Leadership Team/oversight/test.csv",
    drive = getOption('m365filer.spdrive')
  )

mtcars %>%
  upload_sharepoint_file(
    write.csv,
    "Leadership Team/oversight/test.csv"
)

mtcars %>%
  upload_onedrive_file(
    write.csv,
    "Documents/test.csv"
 )
 }