I am trying to download ~200 geotiffs into R using package 'rvest'.
A screenshot of the website:
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")
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.