R - how to use . xlsx and . csv files with onedrive url

Asked

Viewed 41 times

2

I would like to replace the file name for a link that downloads the file directly from onedrive. My intention would be to share with someone only the R script and it could run straight without having to send directly the files used.

library(readxl)

base <- read_excel(**"tabela5938 pib.xlsx"**, col_names = c('Codigo', 'Municipio', 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016))

1 answer

2

Enter Onedrive and in the file context menu take the "Embed" option. It will generate something like:

<iframe src="https://onedrive.live.com/embed?cid=E8F4DCBDA1CF1243&resid=E8F4DCBDA1CF1243%21177&authkey=AAbiQULpERX5A_I" width="98" height="120" frameborder="0" scrolling="no"></iframe>

Copy link and replace embed for download: https://onedrive.live.com/download?cid=.... If the function you use to read the file has URL support, use the direct link, otherwise download and read:

# CSV de exemplo no meu OneDrive
link.csv <- "https://onedrive.live.com/download?cid=E8F4DCBDA1CF1243&resid=E8F4DCBDA1CF1243%21177&authkey=AAbiQULpERX5A_I"

> read.csv(link.csv)
  letra numero
1     A      1
2     B      2
3     C      3
4     D      4

Or by downloading to a temporary file first:

link.xls <- "https://onedrive.live.com/download?cid=E8F4DCBDA1CF1243&resid=E8F4DCBDA1CF1243%21178&authkey=AJMJUl3aej0ZnAk&em=2"

temp <- tempfile()
download.file(link.xls, temp)
readxl::read_xlsx(temp)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.