knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

To install this package you can use the code below:

devtools::install_github('nahfa911/weatherforecas', build_vignettes = TRUE)
library(weatherforecast)

Open Weather Map API

There are two ways to open up the shinyapp.

1. Download the weather shinyapp package

devtools::install_github('nahfa911/shinyweather')
runshinyweather()

2. Run by runGigHub function

# run shinyapp
library(shiny)
runGitHub("shinyweather", "nahfa911")

This package is about working with Web API. The package establish a connection with Web API called Open weather map using R programming language. The chosen API is about weather forecast available for 5 days at any location or city, and it includes weather data every 3 hours.

Depends

This package depends on two other packages:

library(httr)
library(jsonlite)

About Package

The function in the package calls the Web API from the site:

https://openweathermap.org/api

For this purpose we got our API Key first from the site and then after authentication we used it to call our JSON format data. The second step in the implementation is importing a library called httr which is designed to map closely to the underlying HTTP protocol.

Following is the way we called our API:

library(httr)
Respsone_Data <- httr::GET(paste0('http://api.openweathermap.org/data/2.5/forecast?q=',Cityname,
                                            '&cnt=9&units=metric&appid=', key))

Request

cityweather() requires 2 parameters.

api_key = An access token to access the API. Access token can be generated from the website.

cityname = A city name for which the user wants to see the weather.

The package provides an RC class named cityweather used to analyze Open Weather Map data. User can retrieve a city data from the API by calling the following lines of code.

In order to create an object of class, you need to give a character name of the city you want to analyze.

City_Forecast_Object <- weatherforecast::cityweather$new("London")

The package returns the following data:

list content of cities i.e. temperature, latitude, longitude, Max temperature etc.

City_Forecast_Object$content$list

message from the API about the data content.

City_Forecast_Object$content$message

Validation

In this step we are initializing our methods and implementing some checks for validating our API data which are:

City_Forecast_Object$status_code

status_code For checking the response code. It Extract status code from response. 200 response code is for proper data whereas 404 is for error.

City_Forecast_Object$type 

# != 'application/json'

content_type For checking the type of data. It Extract Content type of the response. Here we are checking if our data is of JSON format or not.

City_Forecast_Object$has_error

has_error This part checks for an HTTP error. It returns TRUE if the request fails (status code 400 or above), otherwise FALSE.



nahfa911/weatherforecas documentation built on May 29, 2019, 3:07 a.m.