Error reading csv files from an URL in Markdown

705 views Asked by At

I am trying to download some data from the bank of England website to do some charts. I use read.csv as in the script below and this works fine when I run this in the R console.

    require(xts)
require(PerformanceAnalytics)
url <-  "http://www.bankofengland.co.uk/boeapps/iadb/fromshowcolumns.asp?csv.x=yes&Datefrom=01/JAN/1975&Dateto=now &SeriesCodes=XUDLUSG,XUDLERG&CSVF=TN&UsingCodes=Y&VPD=Y&VFD=N"

datamat <- read.csv(url)
datamat <- na.omit(datamat)
rownames(datamat) <- as.Date(datamat$DATE,format = "%d %B %Y")
datamat <- datamat[,2:3]

datamat <- na.omit(as.xts(datamat))
chart.TimeSeries(datamat,main="")

however when I am trying to generate a report using markdown I get the following error:

Error in file(file, "rt") : cannot open the connection Calls: ... withVisible -> eval -> eval -> read.csv -> read.table -> file Execution halted

The code I use is the same than above aside that it as the Markdown

```{r  getboedata }

require(xts)
require(PerformanceAnalytics)
url <-  "http://www.bankofengland.co.uk/boeapps/iadb/fromshowcolumns.asp?csv.x=yes&Datefrom=01/JAN/1975&Dateto=now &SeriesCodes=XUDLUSG,XUDLERG&CSVF=TN&UsingCodes=Y&VPD=Y&VFD=N"

datamat <- read.csv(url)
datamat <- na.omit(datamat)
rownames(datamat) <- as.Date(datamat$DATE,format = "%d %B %Y")
datamat <- datamat[,2:3]

datamat <- na.omit(as.xts(datamat))
chart.TimeSeries(datamat,main="")


```
0

There are 0 answers