ropensci / rnoaa

R interface to many NOAA data APIs
https://docs.ropensci.org/rnoaa
Other
328 stars 85 forks source link

meteo_nearby_stations error #418

Closed raruggie closed 1 year ago

raruggie commented 1 year ago

I am using meteo_nearby_stations like so:

# this is my lat long dataframe.
test<-structure(list(Site = "Inlet at Mouth", Lat = 42.754942, Long = -76.463351), row.names = 1L, class = "data.frame")

# list of possible stations. I know this is optional but tried it anyway to see if it would get rid of error. 
station_data = ghcnd_stations()

# find closest stations
mon_near_pw <- 
  meteo_nearby_stations(
    lat_lon_df = test,
    lat_colname = "Lat",
    lon_colname = "Long",
    station_data = station_data,
    var = "PRCP",
    year_min = 2011,
    year_max = 2015,
    radius = 100,
  )

and I am getting the following generic error:

Error in `$<-.data.frame`(`*tmp*`, "id", value = character(0)) : 
  replacement has 0 rows, data has 1

The example workflow (https://stackoverflow.com/questions/68878571/how-to-download-precipitation-data-using-rnoaa) works for me but when using my own site I get this error and I don't know why. The class of the lat long columns are numeric. Could it be that there is no data for my location for the time parameters I chose? If this is the case, I still wouldn't expect this error.

Any help is much appreciated. Thank you.

Session info:

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] rnoaa_1.3.8        whitebox_2.3.0     raster_3.6-3      
 [4] FedData_3.0.1.9999 terra_1.6-17       sp_1.6-0          
 [7] sf_1.0-8           lubridate_1.9.2    forcats_1.0.0     
[10] stringr_1.5.0      dplyr_1.1.1        purrr_1.0.1       
[13] readr_2.1.4        tidyr_1.3.0        tibble_3.2.1      
[16] ggplot2_3.4.2      tidyverse_2.0.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0   lattice_0.20-45    colorspace_2.0-3  
 [4] vctrs_0.6.1        generics_0.1.3     utf8_1.2.3        
 [7] XML_3.99-0.8       rlang_1.1.0        e1071_1.7-9       
[10] pillar_1.9.0       glue_1.6.2         httpcode_0.3.0    
[13] withr_2.5.0        DBI_1.1.3          rappdirs_0.3.3    
[16] lifecycle_1.0.3    munsell_0.5.0      gtable_0.3.1      
[19] codetools_0.2-18   tzdb_0.3.0         curl_4.3.2        
[22] class_7.3-20       hoardr_0.5.2       fansi_1.0.4       
[25] triebeard_0.3.0    urltools_1.7.3     Rcpp_1.0.10       
[28] KernSmooth_2.23-20 scales_1.2.1       classInt_0.4-3    
[31] jsonlite_1.8.4     gridExtra_2.3      digest_0.6.28     
[34] hms_1.1.2          stringi_1.7.12     grid_4.1.3        
[37] cli_3.6.1          tools_4.1.3        magrittr_2.0.3    
[40] proxy_0.4-26       crul_1.3           pkgconfig_2.0.3   
[43] ellipsis_0.3.2     data.table_1.14.4  xml2_1.3.3        
[46] timechange_0.2.0   rstudioapi_0.14    R6_2.5.1          
[49] units_0.8-0        compiler_4.1.3
raruggie commented 1 year ago

I figured this out. The column names need to match the examples.