I want to download a .RData file from a development branch of a repo, as part of developing a setup chunk in a .Rmd file that implements a learnr tutorial. When I download the file manually from github, load("./data_download/elic_2016_1.RData")
successfully loads the downloaded object. However, after downloading the .RData file with download.file(), the subsequent load() produces an error,
download.file("https://github.com/pbpearman/r-consortium-proposal/blob/interactive/material/lessons/switzerland-dual-use/data_clean/elic_2016_1.RData", destfile= "./data_download/elic_2016_1.RData", mode = "wb")
load("./data_download/elic_2016_1.RData")
file ‘elic_2016_1.RData’ has magic number ''
Use of save versions prior to 2 is deprecatedError in load("./data_download/elic_2016_1.RData")
bad restore file magic number (file may be corrupted) -- no data loaded
I also tried this, following stackoverflow.com/questions/26108575 :
load(url("https://github.com/pbpearman/r-consortium-proposal/blob/interactive/material/lessons/switzerland-dual-use/data_clean/elic_2016_1.RData"))
Error in load(url("https://github.com/pbpearman/r-consortium-proposal/blob/interactive/material/lessons/switzerland-dual-use/data_clean/elic_2016_1.RData")) : the input does not start with a magic number compatible with loading from a connection
I created the file with my currently installed R version. The file elic_2016_1.RData on Github doesn't appear to be corrupted because the manually downloaded file loads successfully. The same errors occur whether I run the code line-by-line within the chunk, or run each line from the command line. I tried zipping the .RData file and uploading it, but it still was corrupted upon downloading and unzipping.
What's going wrong and how can I download the .RData file from my repo and load it into R?
I am using R version 3.4.2 and RStudio 1.1.383.