Skip to content

Commit

Permalink
Merge pull request #15 from crazycapivara/develop
Browse files Browse the repository at this point in the history
Develop / v0.8.0
  • Loading branch information
crazycapivara authored Nov 2, 2018
2 parents 71be0cc + a915fe5 commit 6f05c8f
Show file tree
Hide file tree
Showing 152 changed files with 39,502 additions and 912 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^docs$
^_pkgdown\.yml$
^.*\.Rproj$
^\.Rproj\.user$
data-raw/
Expand All @@ -9,3 +11,4 @@ TODO.md
docs/
README.rmd
cran-comments.md
vignettes/owmr.Rmd
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
tmp/
inst/doc
16 changes: 12 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Package: owmr
Title: OpenWeatherMap API Wrapper
Version: 0.7.2
Authors@R: person("Stefan", "Kuethe", email = "[email protected]", role = c("aut", "cre"))
Version: 0.8.0
Date: 2018-11-02
Authors@R: c(
person("Stefan", "Kuethe", email = "[email protected]", role = c("aut", "cre")),
person("Amanda", "Dobbyn", role = "ctb")
)
Maintainer: Stefan Kuethe <[email protected]>
Description: Accesses OpenWeatherMap's (owm) <https://openweathermap.org/> API.
'owm' itself is a service providing weather data in the past, in the future and now.
Furthermore, 'owm' serves weather map layers usable in frameworks like 'leaflet'.
Expand All @@ -17,11 +22,14 @@ Depends:
Imports:
magrittr,
httr,
jsonlite
jsonlite,
plyr,
tibble,
tidyr
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
Suggests:
leaflet,
whisker,
Expand Down
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Generated by roxygen2: do not edit by hand

S3method(owmr_as_tibble,default)
S3method(owmr_as_tibble,owmr_forecast_daily)
S3method(owmr_as_tibble,owmr_weather)
export("%$$%")
export("%<>%")
export("%>%")
export(add_owm_tiles)
export(add_weather)
export(cbind_weather)
export(find_cities_by_geo_point)
export(find_city)
export(find_stations_by_geo_point)
export(flatten)
export(flatten_weather)
export(get_current)
export(get_current_for_group)
export(get_current_from_station)
export(get_forecast)
export(get_forecast_daily)
export(get_icon_url)
export(owm_layers)
export(owmr_as_tibble)
export(owmr_settings)
export(parse_columns)
export(remove_prefix)
Expand Down
55 changes: 36 additions & 19 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
# owmr 0.3.0
# owmr 0.8.0

* Added a `NEWS.md` file to track changes to the package.
* Added generic function `owmr_as_tibble` to get similiar-ish and tidy data frames
for all kind of responses
* Removed `find_stations_by_geo_point` and `get_current_from_station` because of a new
_owm stations api_

# owmr 0.4.0
# owmr 0.7.4

* Added function to search owm's city list by city name.
* Added tests for current data.
- Added helper function to fetch 'fresh' data used in tests.
* Fixed bug in `add_owm_tiles`
* `find_stations_by_geo_point` and `get_current_from_station` are not supported anymore because of breaking changes in the owm api for stations. Functions will be removed in a future version.

# owmr 0.4.1
# owmr 0.7.3

* Added function to fetch current weather data for multiple cities at once.
* Added feature to store the api key in an environment variable called `OWM_API_KEY`
* It is still possible to set the key via `owmr_settings`, but it is recommended that you use the environment variable instead

# owmr 0.5.0
# owmr 0.7.2

* Refactored code
* Added function to fetch current weather data for cities around geo point (more or less an alias to `find_city`).
* Marked UTF-8 string in data fixed.
* Updated package description

# owmr 0.6.1
# owmr 0.7.1

* Added function to show weather data on leaflet map.
- Added operator `%$$%` to render template text for popups.
* Fixed false poitives in check for undefined global variable `.` from `magrittr`

# owmr 0.7.0

* Added functions to add owm tiles to leaflet map.
- Note: Performance of owm tile server seems to be low.

# owmr 0.7.1
# owmr 0.6.1

* Fixed false poitives in check for undefined global variable `.` from `magrittr`
* Added function to show weather data on leaflet map.
- Added operator `%$$%` to render template text for popups.

# owmr 0.7.2
# owmr 0.5.0

* Updated package description
* Refactored code
* Added function to fetch current weather data for cities around geo point (more or less an alias to `find_city`).
* Marked UTF-8 string in data fixed.

# owmr 0.4.1

* Added function to fetch current weather data for multiple cities at once.

# owmr 0.4.0

* Added function to search owm's city list by city name.
* Added tests for current data.
- Added helper function to fetch 'fresh' data used in tests.

# owmr 0.3.0

* Added a `NEWS.md` file to track changes to the package.
6 changes: 3 additions & 3 deletions R/city_list.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Look up coordinates and city id in owm's city list.
#'
#' search \code{\link{owm_cities}} dataset by city name
#' and country code
#' Search \code{\link{owm_cities}} dataset by city name
#' and country code.
#'
#' @seealso \code{\link{owm_cities}} dataset
#'
Expand All @@ -16,7 +16,7 @@
#' search_city_list("London", "GB")
#' search_city_list("London")
#' search_city_list("Lond")
search_city_list <- function(city, country_code = ""){
search_city_list <- function(city, country_code = "") {
result <- grepl(city, owmr::owm_cities$nm) &
grepl(country_code, owmr::owm_cities$countryCode)
owmr::owm_cities[result, ]
Expand Down
6 changes: 6 additions & 0 deletions R/current-bbox.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
find_cities_by_bbox <- function(bbox = c(12,32,15,37,10), ...) {
get <- owmr_wrap_get("box/city")
get(bbox = paste0(bbox, collapse = ","), ...) %>%
owmr_parse() %>%
owmr_class("owmr_box_city")
}
14 changes: 7 additions & 7 deletions R/current-multiple.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param city_ids numeric vector containing city ids
#' @param ... see owm api documentation
#'
#' @return list containing data frame with current weather data of cities
#' @return list
#' @export
#'
#' @examples \dontrun{
Expand All @@ -15,31 +15,31 @@
#' result$cnt == nrow(result$list)
#' weather_frame <- result$list
#' }
get_current_for_group <- function(city_ids, ...){
get_current_for_group <- function(city_ids, ...) {
get <- owmr_wrap_get("group")
get(id = paste(city_ids, collapse = ",")) %>%
owmr_parse()
owmr_parse() %>%
owmr_class("owmr_group")
}

#' Find cities by geo point.
#'
#' Get current weather data for a number of cities
#' around given geo point.
#' around a given geo point.
#'
#' @param lat latitude of geo point
#' @param lon longitude of geo point
#' @param cnt number of cities
#' @param ... see owm api documentation
#'
#' @return list containing data frame with weather data
#'
#' @return list
#' @export
#'
#' @seealso \code{\link{find_city}}
#'
#' @examples \dontrun{
#' find_cities_by_geo_point(lat = 51.50853, lon = -0.12574, cnt = 5)
#' }
find_cities_by_geo_point <- function(lat, lon, cnt = 3, ...){
find_cities_by_geo_point <- function(lat, lon, cnt = 3, ...) {
find_city(lat = lat, lon = lon, cnt = cnt, ...)
}
12 changes: 8 additions & 4 deletions R/current.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#' get_current(lon = -0.09184, lat = 51.51279)
#' get_current(zip = "94040,US")
#' }
get_current <- function(city = NA, ...){
get_current <- function(city = NA, ...) {
get <- owmr_wrap_get("weather")
get(city, ...) %>% owmr_parse()
get(city, ...) %>%
owmr_parse() %>%
owmr_class("owmr_weather")
}

#' Find city by name or coordinates.
Expand All @@ -37,7 +39,9 @@ get_current <- function(city = NA, ...){
#' find_city("London,UK")
#' find_city(lat = 51.50853, lon = -0.12574, cnt = 5)
#' }
find_city <- function(city = NA, ...){
find_city <- function(city = NA, ...) {
get <- owmr_wrap_get("find")
get(city, ...) %>% owmr_parse()
get(city, ...) %>%
owmr_parse() %>%
owmr_class("owmr_find")
}
8 changes: 7 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
#' \item{lon}{longitude}
#' \item{countryCode}{two letter country code}
#' }
#' @source \url{http://openweathermap.org/help/city_list.txt}
#' @source \url{http://bulk.openweathermap.org/sample/city.list.json.gz}
#'
# NOTE: UTF-8 string found in `owm_cities$nm[7053]`
# Metabetchouan-Lac-a-la-Croix, needs to be fixed in case dataset
# is updated
"owm_cities"

#' List of available owm weather map layers.
#'
#' @seealso
#' \url{https://openweathermap.org/api/weathermaps}
"owm_layers"
27 changes: 9 additions & 18 deletions R/fetch_test_data.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
folder_test_data <- "tests/testthat/data/"

# save data to test folder
save_test_data <- function(x, filename){
save_test_data <- function(x, filename) {
(fn <- paste0(folder_test_data, filename)) %>%
saveRDS(x, .)
sprintf("data written to %s\n", fn) %>% cat
sprintf("data written to %s\n", fn) %>% cat()
}

save_current <- function(){
save_current <- function() {
get_current("Kassel") %>%
save_test_data("current.rds")
}

save_current_multiple <- function(){
save_current_multiple <- function() {
get_current_for_group(c(2831088, 2847639, 2873291)) %>%
save_test_data("current_multiple.rds")
}

save_stations_multiple <- function(){
find_stations_by_geo_point(lat = 51.31667, lon = 9.5, cnt = 15) %>%
save_test_data("stations_multiple.rds")
}

# get (raw) response to be used in mockups
# should be done for other responses as well
get_response <- function(path = "weather", city = NA, ...){
get_response <- function(path = "weather", city = NA, ...) {
mock_url <- "Hi folks!"
response <- owmr_wrap_get(path)(city, ...)
response$url <- mock_url -> response$request$url
Expand All @@ -39,19 +34,15 @@ get_response <- function(path = "weather", city = NA, ...){
# to run tests after data was fetched succesfully
#
### @export
#
fetch_test_data <- function(run_tests = TRUE){
#save_current()
#save_current_multiple()
#save_stations_multiple()
fetch_test_data <- function(run_tests = TRUE) {
save_current()
save_current_multiple()
get_response("weather", "Kassel") %>%
save_test_data("response-current.rds")
get_response("forecast", "London") %>%
save_test_data("response-forecast.rds")
get_response("station/find", lat = 51.31667, lon = 9.5, cnt = 7) %>%
save_test_data("response-stations_multiple.rds")
# run tests
if(run_tests){
if (run_tests) {
testthat::test_dir("tests/testthat", reporter = "tap")
}
}
10 changes: 5 additions & 5 deletions R/forecast-daily.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' Get daily forcast data up to 16 days.
#' Get daily forecast data up to 16 days.
#'
#' @inheritParams get_current
# @param city city name or id
# @param ... see owm api documentation
#'
#' @return list
#' @export
Expand All @@ -12,7 +10,9 @@
#' result <- get_forecast_daily("London", cnt = 9)
#' forecast_frame <- result$list
#' }
get_forecast_daily <- function(city = NA, ...){
get_forecast_daily <- function(city = NA, ...) {
get <- owmr_wrap_get("forecast/daily")
get(city, ...) %>% owmr_parse()
get(city, ...) %>%
owmr_parse() %>%
owmr_class("owmr_forecast_daily")
}
8 changes: 4 additions & 4 deletions R/forecast.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' Get 3h forecast data.
#'
#' @inheritParams get_current
# @param city city name or id
# @param ... see owm api documentation
#'
#' @return list
#' @export
Expand All @@ -13,7 +11,9 @@
#' get_forecast("London", cnt = 10)
#' get_forecast(lat = -22.90278, lon = -22.90278, cnt = 3, units = "metric")
#' }
get_forecast <- function(city = NA, ...){
get_forecast <- function(city = NA, ...) {
get <- owmr_wrap_get("forecast")
get(city, ...) %>% owmr_parse()
get(city, ...) %>%
owmr_parse() %>%
owmr_class("owmr_forecast")
}
Loading

0 comments on commit 6f05c8f

Please sign in to comment.