11

I am trying to import a RDS file into RStudio in Windows, I tried following this example, which is for Rdata, and I tried both methods:

Method 1:

githubURL <- ("https://github.com/derek-corcoran-barrios/LastBat/blob/master/best2.My.Lu2.rds")
BestMyyu <- readRDS(url(githubURL))

Method 2:

githubURL <- ("https://github.com/derek-corcoran-barrios/LastBat/blob/master/best2.My.Lu2.rds")
download.file(githubURL,"best2.My.Lu2.rds")
BestMyyu <- readRDS("best2.My.Lu2.rds")

I've looked for other threads and I have not found any other example

Community
  • 1
  • 1
Derek Corcoran
  • 3,930
  • 2
  • 25
  • 54

1 Answers1

7

In 2nd method you just need to add method="curl" and also change the url to point to raw (Download link on the page)

githubURL <- ("https://raw.githubusercontent.com/derek-corcoran-barrios/LastBat/master/best2.My.Lu2.rds")
download.file(githubURL,"best2.My.Lu2.rds", method="curl")
BestMyyu <- readRDS("best2.My.Lu2.rds")

If you don't have curl installed, you can get it from here

Ivan
  • 3,781
  • 16
  • 20
  • thank you, I am almost there, I tried It, but for some reason after I download it (I see the folder and its there, and it looks like the format), I do the following and get the error. BestMyyu <- readRDS("best2.My.Lu2.rds") Error in readRDS("best2.My.Lu2.rds") : unknown input format – Derek Corcoran Oct 19 '16 at 23:42
  • 1
    @DerekCorcoran updated. Github url for 'Download' should be there, otherwise what we are downloading is html page thus you see incorrect format message. Please let me know if that worked – Ivan Oct 20 '16 at 07:27
  • thank you @Ivan, that worked perfectly, how did you get that downloadable URL? when I clicked in see raw in the github before you posted this it downloaded the file without changing the URL, is it always just changing the first part to raw.githubusercontent.com? thanks for the help!! – Derek Corcoran Oct 20 '16 at 12:41
  • 1
    @DerekCorcoran there is 'Download' button there, I right clicked it and got the URL – Ivan Oct 20 '16 at 12:51
  • 1
    thank you @Ivan I can't believe I didn't think of that, everything is very obvious when someone else points it out isn't it? You've been very helpful – Derek Corcoran Oct 20 '16 at 15:38