Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading Excel File Using R

Tags:

r

excel

download

I am trying to download an Excel file from Central bank of Colombia website, but it seems that the usual download.file function couldn't do the job.

For example, I am trying to download the first file "Serie historica" on this page: http://www.banrep.gov.co/es/indice-tasa-cambio-real

The link to the file is as follows, which I used in the download.file function http://obieebr.banrep.gov.co/analytics/saw.dll?Download&Format=excel2007&Extension=.xls&BypassCache=true&path=%2Fshared%2FSeries%20Estad%c3%adsticas_T%2F1.%20Indice%20de%20Tasa%20de%20Cambio%20Real%2F1.1.%20Serie%20historica_IQY&SyncOperation=1&NQUser=publico&NQPassword=publico

The command I used is:

download.file(filepath, destfile, quiet=FALSE, mode="wb")
like image 842
Gary H Avatar asked Jan 29 '23 11:01

Gary H


1 Answers

I hope this example will guide you

library(readxl)
library(httr)
url1<-'https://evs.nci.nih.gov/ftp1/CDISC/SDTM/SDTM%20Terminology.xls'
GET(url1, write_disk(tf <- tempfile(fileext = ".xls")))
df <- read_excel(tf, 2L)
str(df)

If you can download the file you could read it as follows

library(readxl)
datos <- read_xlsx("C:/Users/USER/Downloads/1.1. Serie historica_IQY.xlsx", skip = 8, n_max = 369)
like image 118
Rafael Díaz Avatar answered Feb 01 '23 09:02

Rafael Díaz