ropensci / rnoaa

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

ghcn_stations() returns an extra empty row #267

Closed joeroe closed 6 years ago

joeroe commented 6 years ago

The last row in the tibble returned by ghcnd_stations() consists solely of NAs:

> stations <- rnoaa::ghcnd_stations()
> which(is.na(stations$id))
[1] 607870
> stations[607870,]
# A tibble: 1 x 11
  id    latitude longitude elevation state name  gsn_flag wmo_id element first_year last_year
  <chr>    <dbl>     <dbl>     <dbl> <chr> <chr> <chr>    <chr>  <chr>        <int>     <int>
1 NA          NA        NA        NA NA    NA    NA       NA     NA              NA        NA

Obviously this isn't hard to deal with, but it causes a minor annoyance when you want to pass the output straight to base R functions where na.rm defaults to false, e.g.:

> max(stations$latitude)
[1] NA

Or other functions that don't like NAs, e.g.:

> sf::st_as_sf(stations, coords = c("longitude", "latitude", "elevation"), crs = 4326) 
Error in st_as_sf.data.frame(stations, coords = c("longitude", "latitude",  : 
  missing values in coordinates not allowed
Session Info ```r Session info --------------------------------------------------------------------------------------- setting value version R version 3.5.1 (2018-07-02) system x86_64, linux-gnu ui RStudio (1.1.456) language (EN) collate en_GB.UTF-8 tz Europe/Copenhagen date 2018-07-30 Packages ------------------------------------------------------------------------------------------- package * version date source assertthat 0.2.0 2017-04-11 CRAN (R 3.5.1) backports 1.1.2 2017-12-13 CRAN (R 3.5.1) base * 3.5.1 2018-07-02 local bindr 0.1.1 2018-03-13 CRAN (R 3.5.1) bindrcpp 0.2.2 2018-03-29 CRAN (R 3.5.1) broom 0.5.0 2018-07-17 CRAN (R 3.5.1) cellranger 1.1.0 2016-07-27 CRAN (R 3.5.1) class 7.3-14 2015-08-30 CRAN (R 3.5.1) classInt 0.2-3 2018-04-16 CRAN (R 3.5.1) cli 1.0.0 2017-11-05 CRAN (R 3.5.1) colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1) compiler 3.5.1 2018-07-02 local crayon 1.3.4 2017-09-16 CRAN (R 3.5.1) curl 3.2 2018-03-28 CRAN (R 3.5.1) datasets * 3.5.1 2018-07-02 local DBI 1.0.0 2018-05-02 CRAN (R 3.5.1) devtools 1.13.6 2018-06-27 CRAN (R 3.5.1) digest 0.6.15 2018-01-28 CRAN (R 3.5.1) dplyr * 0.7.6 2018-06-29 CRAN (R 3.5.1) e1071 1.7-0 2018-07-28 CRAN (R 3.5.1) fansi 0.2.3 2018-05-06 CRAN (R 3.5.1) forcats * 0.3.0 2018-02-19 CRAN (R 3.5.1) ggplot2 * 3.0.0 2018-07-03 CRAN (R 3.5.1) glue 1.3.0 2018-07-17 CRAN (R 3.5.1) graphics * 3.5.1 2018-07-02 local grDevices * 3.5.1 2018-07-02 local grid 3.5.1 2018-07-02 local gridExtra 2.3 2017-09-09 CRAN (R 3.5.1) gtable 0.2.0 2016-02-26 CRAN (R 3.5.1) haven 1.1.2 2018-06-27 CRAN (R 3.5.1) hms 0.4.2 2018-03-10 CRAN (R 3.5.1) hoardr 0.2.0 2017-05-10 CRAN (R 3.5.1) httr 1.3.1 2017-08-20 CRAN (R 3.5.1) jsonlite 1.5 2017-06-01 CRAN (R 3.5.1) lattice 0.20-35 2017-03-25 CRAN (R 3.5.1) lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.1) lubridate 1.7.4 2018-04-11 CRAN (R 3.5.1) magrittr 1.5 2014-11-22 CRAN (R 3.5.1) memoise 1.1.0 2017-04-21 CRAN (R 3.5.1) methods * 3.5.1 2018-07-02 local mime 0.5 2016-07-07 CRAN (R 3.5.1) modelr 0.1.2 2018-05-11 CRAN (R 3.5.1) munsell 0.5.0 2018-06-12 CRAN (R 3.5.1) nlme 3.1-137 2018-04-07 CRAN (R 3.5.1) pillar 1.3.0 2018-07-14 CRAN (R 3.5.1) pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.1) plyr 1.8.4 2016-06-08 CRAN (R 3.5.1) purrr * 0.2.5 2018-05-29 CRAN (R 3.5.1) R6 2.2.2 2017-06-17 CRAN (R 3.5.1) rappdirs 0.3.1 2016-03-28 CRAN (R 3.5.1) Rcpp 0.12.17 2018-05-18 CRAN (R 3.5.1) readr * 1.1.1 2017-05-16 CRAN (R 3.5.1) readxl 1.1.0 2018-04-20 CRAN (R 3.5.1) rlang 0.2.1 2018-05-30 CRAN (R 3.5.1) rnoaa 0.7.0 2017-05-06 CRAN (R 3.5.1) rstudioapi 0.7 2017-09-07 CRAN (R 3.5.1) rvest 0.3.2 2016-06-17 CRAN (R 3.5.1) scales 0.5.0 2017-08-24 CRAN (R 3.5.1) sf 0.6-3 2018-05-17 CRAN (R 3.5.1) spData 0.2.9.0 2018-06-17 CRAN (R 3.5.1) stats * 3.5.1 2018-07-02 local stringi 1.2.4 2018-07-20 CRAN (R 3.5.1) stringr * 1.3.1 2018-05-10 CRAN (R 3.5.1) tibble * 1.4.2 2018-01-22 CRAN (R 3.5.1) tidyr * 0.8.1 2018-05-18 CRAN (R 3.5.1) tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.1) tidyverse * 1.2.1 2017-11-14 CRAN (R 3.5.1) tools 3.5.1 2018-07-02 local uncertainlandscapes 0.0.0.9000 2018-07-30 local (@NA) units 0.6-0 2018-06-09 CRAN (R 3.5.1) utf8 1.1.4 2018-05-24 CRAN (R 3.5.1) utils * 3.5.1 2018-07-02 local withr 2.1.2 2018-03-15 CRAN (R 3.5.1) XML 3.98-1.12 2018-07-15 CRAN (R 3.5.1) xml2 1.2.0 2018-01-24 CRAN (R 3.5.1) yaml 2.1.19 2018-05-01 CRAN (R 3.5.1) ```
sckott commented 6 years ago

thanks for this @joeroe ! can replicate with CRAN version and dev version.

will fix

sckott commented 6 years ago

the latest commit should fix it, let me know if not