-1

I am trying to download ~200 geotiffs into R using package 'rvest'.

A screenshot of the website:

enter image description here

I am using this code:

    library(rvest)

    setwd("path-to-my-directory")

    url <- "https://username:[email protected]/geotiff" 

    page <- read_html(url)

    files <- page %>% 
         html_nodes("a") %>%
         html_attr("href")

    for(i in 2:length(files)){  
    u <- paste(url,files[i], sep="/")  
    download.file(u,files[i], mode = "wb")

When I run the code it does download all the geotiffs. However, when I try to open them using the 'raster' package, I get this error

    file <- raster("path-to-file.geotiff")

enter image description here

I believe something is going wrong in the bulk download step using rvest, because if I instead download a geotiff from the website by clicking on it, I can open it as a raster in R without issue.

I have looked at the help docs for the rvest functions and have been unable to find a solution.

6
  • It is kind of hard to reproduce the issue based on your reprex! Would you mind editing your question to include what website you are using?
    – Josh Allen
    Commented Jun 25 at 23:06
  • 1
    What was wrong with the answer in your previous question? stackoverflow.com/questions/78669462/…. Why are you asking the same question again?
    – Dave2e
    Commented Jun 25 at 23:10
  • Sorry everyone, the website is password protected so unfortunately I cannot provide a link to it
    – sbliss
    Commented Jun 25 at 23:11
  • 1
    In my previous question I was trying to generalize so I didn't have to refer to the specific website because it is password protected. But I've realized that was a mistake as it wasn't clear enough, and the issue is not tiff vs geotiff. The files are geotiffs
    – sbliss
    Commented Jun 25 at 23:12
  • Have you checked sizes and pethaps content of those downloaded files? There's some chance there's just some html with an error message
    – margusl
    Commented Jun 26 at 6:05

0

Browse other questions tagged or ask your own question.