1

I am trying to download 'Landsat.rar` file (included 6 Landsat bands) and unzip it directly in r, but It doesn't work as I expected. Thank you for your help!

library(raster)

ls_url<-"https://github.com/tuyenhavan/Landsat-Data/blob/LS7/Landsat.rar"

temp<-tempfile()

download.file(ls_url,temp)

unzip(temp,"tif$")

myls<-stack("tif$")
Tuyen
  • 977
  • 1
  • 8
  • 23
  • 2
    Possible duplicate of [How download and unzip raster data (Landsat) in r directly from github](https://stackoverflow.com/questions/44926076/how-download-and-unzip-raster-data-landsat-in-r-directly-from-github) – G5W Jul 05 '17 at 13:57

1 Answers1

2

Especially if you are using Windows, it might be that you need to use the binary mode in download.file:

download.file(ls_url, temp, mode="wb")

otherwise the file gets corrupted.

Also, the URL you are using is incorrect. You used the one for the web interface. If you want to get the file itself you need to use (check the link associated with the "Download" button):

https://github.com/tuyenhavan/Landsat-Data/raw/LS7/Landsat.rar

Finally, unzip() doesn't know how to deal with rar archive files. If you created this archive yourself, use the zip format instead; or unrar the file with another program (that you could call from R using system()).

fmic_
  • 2,281
  • 16
  • 23