I would like to be able to pull files out of my project's Sharepoint directly with R to avoid needing to manually download many files repeatedly. Is there a way to do this? I've tried methods like:

read_excel("https://company.sharepoint.com/sites/Project/Shared Documents/Folder/document.xlsx", "Sheet1")

download(url = "https://company.sharepoint.com/sites/Project/Shared Documents/Folder/document.txt", destfile = "localfile.txt")

webpage <- getURL("https://company.sharepoint.com/sites/Project/Shared Documents/Folder/document.txt", userpwd = "username:password")
tc <- textConnection(webpage)

These all result in some form of Error 400, file not found, etc. I've looked into using the REST api with httr as well but haven't gotten anything but failure to receive handshake so far. I know the URL I'm using at least points to the right file because it works when pasted into a browser. I'm not sure if what I'm trying is incorrect or incorrectly formatted or even possible, honestly. Any help is appreciated.

1 Answer 1


Have you tried replacing the spaces in these addresses?

Try it like:

webpage <- getURL("https://company.sharepoint.com/sites/Project/Shared%20Documents/Folder/document.txt", userpwd = "username:password")
tc <- textConnection(webpage)

Then it should read the text document into webpage variable.

I also recommend using httr or RCurl libraries for https authorization.

Edit: Hello again, the code below helps you to get the document from sharepoint server via httr library.

url <- "https://something.company.com/dir/dir/dir/username/Shared%20Documents/some_more_directory/text.txt"
r <- GET(url, authenticate("username","password",type="any"))

From the "r$content" you can easily read the text in binary format, then you may convert the binary content you've got from the sharepoint server with

text_file <- str(content(r, "text"))

Best wishes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.