5

I have CSV files in a folder on Office 365 Sharepoint that I would like to import into R. In base R I get:

> test <- 
read.csv("https://MYURL/:x:/r/sites/MYSITE/Shared%20Documents/Q_10_2018.csv?
d=w5cbc38ea43c347689ec6d59a8285d769&csf=1&e=tZ6Lep",header=TRUE)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open URL 
'https://MYURL.sharepoint.com/:x:/r/sites/MYSITE/Shared%20Documents/
Q_10_2018.csv?d=w5cbc38ea43c347689ec6d59a8285d769&csf=1&e=tZ6Lep': HTTP 
status was '403 FORBIDDEN'

With read_csv I get:

> test <- 
read_csv("https://MYURL/:x:/r/sites/MYSITE/Shared%20Documents/Q_10_2018.csv?
d=w5cbc38ea43c347689ec6d59a8285d769&csf=1&e=tZ6Lep")
Error in open.connection(con, "rb") : HTTP error 403.

I would like to offer a reproducible problem but because these are internal sites, I am not able to provide the full URL and give access to our corporate server. Also, I can't find and questions here or other documentation that tells me if this goal is even attainable.

Does anyone have any clues? Thanks in advance.

mysteRious
  • 4,102
  • 2
  • 16
  • 36
  • The web path is probably not going to work due to OneDrive security and also that it's not a direct link to the raw file. Can you navigate to the file via File Explorer? If you use a path like `C://Users/user/OneDrive/folder/file.csv` it should work – Mako212 Sep 14 '18 at 19:16

2 Answers2

0

You might be able to do this via httr:

library(httr)
response <- GET("http://address-to-file", authenticate("Username", "password", "any"))
text_file <- str(content(response, "text"))

Alternatively, you could try using download.file into a temp directory first:

download.file("http://address-to-file", destfile = "/tmp/test.csv")
read.csv("/tmp/test.csv")
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116
  • possibly promising! managed to get in, but it's downloading document metadata. STILL, I feel halfway there. Going to find my Azure sysadmin on Monday and see if there's a switch to flip on that side. Will provide update then. Thanks :) – mysteRious Sep 14 '18 at 21:53
0

Try this:

x <- read.csv(url("https://MYURL/:x:/r/sites/MYSITE/Shared%20Documents/Q_10_2018.csv..."))

source

Víctor Cortés
  • 473
  • 4
  • 9