Accessing Excel file from Sharepoint with R

I use

library(readxl)
read_excel('//companySharepointSite/project/.../ExcelFilename.xlsx', 'Sheet1', skip=1)

Note, no https:, and sometimes I have to open the file first (i.e., cut and paste //companySharepointSite/project/.../ExcelFilename.xlsx into my browser's address bar)


I found that other answers did not work for me, perhaps because I am on a Mac, which obviously does not play as well with Microsoft products such as Sharepoint.

Ended up having to split it into two pieces: first download the Excel file to disk and then separately read that Excel file.

library(httr)
library(readxl)

# the URL of your sharepoint file
file_url <- "https://yoursharepointsite/Documents/yourfile.xlsx"

# save the excel file to disk
GET(file_url, 
    authenticate(active_directory_username, active_directory_password, "ntlm"),
    write_disk("tempfile.xlsx", overwrite = TRUE))

# save to dataframe
df <- read_excel("tempfile.xlsx")
df

# remove excel file from disk
file.remove("tempfile.xlsx")

This gets the job done, though would be interested if anyone knows how to avoid the interim step of writing to disk.

N.B. Depending on your specific machine/network/Sharepoint configuration, you may also be able to just use authenticate(":",":","ntlm") per this answer.