Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rm(list=ls(all=TRUE))
- library('purrr')
- years <- c(1980:1981)
- days <- c(001:002)
- walk(years, function(x) {
- map(x, ~sprintf("https://hydro1.gesdisc.eosdis.nasa.gov/data/NLDAS/NLDAS_MOS0125_H.002/%s/%s/.grb", years, days)) %>%
- flatten_chr() -> urls
- download.file(urls, basename(urls), method="libcurl")
- })
- Error:
- Error in download.file(urls, basename(urls), method = "libcurl") :
- download.file(method = "libcurl") is not supported on this platform
- The supported ‘method’s do change: method ‘libcurl’ was introduced
- in R 3.2.0 and is still optional on Windows - use
- ‘capabilities("libcurl")’ in a program to see if it is available.
- library(purrr)
- library(httr)
- library(rvest)
- years <- c(1980:1981)
- days <- sprintf("%03d", 1:2)
- sprintf("https://hydro1.gesdisc.eosdis.nasa.gov/data/NLDAS/NLDAS_MOS0125_H.002/%s/%%s/", years) %>%
- map(~sprintf(.x, days)) %>%
- flatten_chr() %>%
- map(~{
- base_url <- .x
- sprintf("%s/%s", base_url, read_html(.x) %>%
- html_nodes(xpath=".//a[contains(@href, '.grb')]") %>%
- html_attr("href"))
- }) %>%
- flatten_chr() %>%
- discard(~grepl("xml$", .)) %>%
- walk(~{
- if (!file.exists(basename(.x))) {
- GET(
- url = .x,
- write_disk(basename(.x), overwrite=TRUE),
- authenticate(user = "bob@rud.is", password = "KtkJgaNbHE6iUbX&eM"),
- progress()
- )
- }
- })
Add Comment
Please, Sign In to add comment