简体   繁体   English

从R中的sharepoint文件夹读取excel文件

[英]Reading excel files from sharepoint folder in R

Currently I am building the automated process to clean and transform excel data from sharepoint using R. I have trouble reading excel files from sharepoint in R. I read a couple of posts ( Accessing Excel file from Sharepoint with R , for instance), and tried a couple of suggestions, but none worked for me.目前,我正在构建自动化流程,以使用 R 从共享点清理和转换 excel 数据。我无法从 R 中的共享点读取 excel 文件。我阅读了几篇文章(例如, 使用 R 从 Sharepoint 访问 Excel 文件),并尝试一些建议,但没有一个对我有用。 The all error message are "Path" does not exist.所有的错误信息都是“路径”不存在。 Could someone give me some light for that?有人可以给我一些启发吗?

I ran GET() and the link works:我运行了 GET() 并且链接有效:

r <- GET(url, authenticate("window_username","window_password",type="any"))

I run into the same issue using the following code to get the info from an excel on this sharepoint site with the same error as the one in the original question:我遇到了同样的问题,使用以下代码从这个 sharepoint 站点上的 excel 获取信息,错误与原始问题中的错误相同:

data <- read_excel(url)

Any feedback would be greatly appreciated.任何反馈将不胜感激。

To make access to SharePoint files easy you should sync the sites from the web app to File Explorer.为了轻松访问 SharePoint 文件,您应该将网站从 Web 应用程序同步到文件资源管理器。 Addresses for these cloud resources that have been synced are commonly of the form: C:\Users\username\My Org\My Teams Group - General\Project\My Excel.xlsx This can create a problem when the code is run multiple users.这些已同步的云资源的地址通常采用以下形式:C:\Users\username\My Org\My Teams Group - General\Project\My Excel.xlsx 当代码运行多个用户时,这可能会产生问题。 Whilst https addresses for cloud locations may work in File Explorer they do not work directly within R packages.虽然云位置的 https 地址可以在文件资源管理器中使用,但它们不能直接在 R 包中使用。 If relative addresses don't work you can make the code user agnostic by setting the username as a variable or returning the homepath with Sys.getenv() function.如果相对地址不起作用,您可以通过将用户名设置为变量或使用 Sys.getenv() 函数返回 homepath 来使代码用户不可知。

library(openxlsx)
username <- Sys.getenv("USERNAME")
sharepoint_address <- "/My Org/My Teams Group – General/Project/My Excel.xlsx"
df <- read.xlsx(xlsxFile = paste0("C:/Users/",username,sharepoint_address), sheet = "Raw Data”)
# More elegantly 
df <- read.xlsx(xlsxFile = paste0(Sys.getenv("HOMEPATH"),sharepoint_address), sheet = "Raw Data”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM