0

How can I read RData with httr? I tried a couple of things but I got error

a)

download.file(downloadURL, "temp.rData")
load("temp.rData")

b)

bin = getBinaryURL(downloadURL, ...yourOtherParams...) 
writeBin(bin, "temp.rData")  
load("temp.rData")

from thread Download .RData and .csv files from FTP using RCurl (or any other method)

and also using httr

c)

  a=GET("https://github.com/tvganesh/yorkrData/blob/master/IPL/IPL-T20-matches/Chennai%20Super%20Kings-Deccan%20Chargers-2008-05-06.RData")
  writeBin(a$content,"aa.RData")
  load("aa.RData")

but I get the error

 Error: bad restore file magic number (file may be corrupted) -- no data loaded
 In addition: Warning message:
  file ‘t.rData’ has magic number '<'
  Use of save versions prior to 2 is deprecated

How can I fix this?

Thanks Ganesh

Community
  • 1
  • 1
Tinniam V. Ganesh
  • 1,979
  • 6
  • 26
  • 51
  • Try the `mode="wb"` argument to `download.file()` to force binary transfer. Also consider operating-system level tools: `ftp`, `scp`, ... – Dirk Eddelbuettel Aug 31 '16 at 12:19
  • @Dirk, yes I had used mode="wb". It did not help – Tinniam V. Ganesh Aug 31 '16 at 12:21
  • `load(url("https://github.com/tvganesh/yorkrData/raw/master/IPL/IPL-T20-matches/Chennai%20Super%20Kings-Deccan%20Chargers-2008-05-06.RData"))` – jogo Aug 31 '16 at 12:35
  • @jojo - I get "Error: the input does not start with a magic number compatible with loading from a connection" – Tinniam V. Ganesh Aug 31 '16 at 12:38
  • @TinniamV.Ganesh Which version of R you are using? I tested with R3.3.1 without any problem. (I get a dataframe `overs` from the RData-file.) – jogo Aug 31 '16 at 12:40
  • @jojo - Strange. I am also using R3.3.1. Also tried in another system "get the magic number issue".By the way overs data frame is correct. – Tinniam V. Ganesh Aug 31 '16 at 12:47
  • Taking the url to the comments here it breaks. I copied the url from the Download-button of the github-page. – jogo Aug 31 '16 at 12:54
  • @jojo - It works! Your URL has "raw" wheres mine has "blob" With this URL it works You can answer and I will accept. – Tinniam V. Ganesh Aug 31 '16 at 12:59

1 Answers1

1

This worked for me:

load(url("https://github.com/tvganesh/yorkrData/raw/master/IPL/IPL-T20-matches/Chennai%20Super%20Kings-Deccan%20Chargers-2008-05-06.RData"))

I get a dataframe overs from the RData-file.
The url is taken from the Download-button of the github-page to get the raw file.

jogo
  • 12,469
  • 11
  • 37
  • 42