I need to download weather data from NASA’s POWER (Prediction Of Worldwide Energy Resource). The package nasapower is a package developed for data retrieval using R. I need to download many locations (lat, long coordinates). To do this I tried a simple loop with three locations as a reproducible example.
library(nasapower) data1 <- read.csv(text = " location,long,lat loc1, -56.547, -14.2427 loc2, -57.547, -15.2427 loc3, -58.547, -16.2427") i=1 all.weather <- data.frame() for (i in seq_along(1:nrow(data1))) { weather.data <- get_power(community = "AG", lonlat = c(data1$long[i],data1$lat[i]), dates = c("2015-01-01", "2015-01-10"), temporal_average = "DAILY", pars = c("T2M_MAX")) all.weather <-rbind(all.weather, weather.data) } This works perfect. The problem is that I am trying to mimic this using purrr::map since I want to have an alternative within tidyverse. This is what I did but it does not work:
library(dplyr) library(purrr) all.weather <- data1 %>% group_by(location) %>% map(get_power(community = "AG", lonlat = c(long, lat), dates = c("2015-01-01", "2015-01-10"), temporal_average = "DAILY", site_elevation = NULL, pars = c("T2M_MAX"))) I got the following error:
Error in isFALSE(length(lonlat != 2)) : object 'long' not found Any hint on how to run this using purrr?
get_powercompliant with tidy eval ? if not, you may have to specify data1$long, data1$lat...