Guest User

Untitled

a guest
Nov 9th, 2017
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. rm(list=ls(all=TRUE))
  2.  
  3. library('purrr')
  4.  
  5. years <- c(1980:1981)
  6. days <- c(001:002)
  7.  
  8. walk(years, function(x) {
  9. map(x, ~sprintf("https://hydro1.gesdisc.eosdis.nasa.gov/data/NLDAS/NLDAS_MOS0125_H.002/%s/%s/.grb", years, days)) %>%
  10. flatten_chr() -> urls
  11. download.file(urls, basename(urls), method="libcurl")
  12. })
  13.  
  14.  
  15. Error:
  16. Error in download.file(urls, basename(urls), method = "libcurl") :
  17. download.file(method = "libcurl") is not supported on this platform
  18.  
  19. The supported ‘method’s do change: method ‘libcurl’ was introduced
  20. in R 3.2.0 and is still optional on Windows - use
  21. ‘capabilities("libcurl")’ in a program to see if it is available.
  22.  
  23. library(purrr)
  24. library(httr)
  25. library(rvest)
  26.  
  27. years <- c(1980:1981)
  28. days <- sprintf("%03d", 1:2)
  29.  
  30. sprintf("https://hydro1.gesdisc.eosdis.nasa.gov/data/NLDAS/NLDAS_MOS0125_H.002/%s/%%s/", years) %>%
  31. map(~sprintf(.x, days)) %>%
  32. flatten_chr() %>%
  33. map(~{
  34. base_url <- .x
  35. sprintf("%s/%s", base_url, read_html(.x) %>%
  36. html_nodes(xpath=".//a[contains(@href, '.grb')]") %>%
  37. html_attr("href"))
  38. }) %>%
  39. flatten_chr() %>%
  40. discard(~grepl("xml$", .)) %>%
  41. walk(~{
  42. if (!file.exists(basename(.x))) {
  43. GET(
  44. url = .x,
  45. write_disk(basename(.x), overwrite=TRUE),
  46. authenticate(user = "bob@rud.is", password = "KtkJgaNbHE6iUbX&eM"),
  47. progress()
  48. )
  49. }
  50. })
Add Comment
Please, Sign In to add comment