Hi all,
I ran into a strange issue where knitr seems to intermittently throw errors when running readLines on a URL. The below line works in console every time, but it seems to fail 4 out of 5 times when I run it in knitr:
readLines("https://www.reddit.com/r/sports/top.json?t=month&limit=100", warn = FALSE)
And here is the full knitr file:
---
title: "testing"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r run, include=TRUE}
x <- readLines("https://www.reddit.com/r/sports/top.json?t=month&limit=100", warn = FALSE)
```
To add mystery to this problem, I noticed that some URLs tend to do better than others, e.g. if I use the following URL: https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv (iris dataset) then it seems to work every time, whereas reddit does not. Perhaps is has something to do with the response time from the server.
Has anyone encountered this problem? Any ideas how to fix this?
Many thanks in advance