Skip to content

Commit

Permalink
Version 0.5.0. On CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
Ram-N committed Jun 7, 2017
1 parent 60cd852 commit be0e6af
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 17 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
.travis.yml
^cran-comments\.md$
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ Description: Functions that help in fetching weather data from
weather data (temperature, pressure etc.) for any weather related analysis.
URL: http://ram-n.github.io/weatherData/
BugReports: https://github.com/ram-n/weatherData/issues
Version: 0.5
Version: 0.5.0
Date: 2017-05-16
Authors@R: person("Ram", "Narasimhan", email = "[email protected]",
role = c("aut", "cre"))
Suggests:
testthat
Depends: R (>= 2.10)
Imports:
curl,
plyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(getDetailedWeather)
export(getStationCode)
export(getSummarizedWeather)
export(getWeatherForDate)
export(getWeatherForMultipleYears)
export(getWeatherForYear)
export(showAvailableColumns)
import(curl)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

* Fixed station_type = "ID" bug. Many features were not working.

* `curl` option is now ready for CRAN. (This has been on github for months.)
* `curl` option takes care of 'https' (This has been on github for months.)

* Added a warning for multiple year fetches. (WeatherUnderground doesn't allow very large CSV files.)
5 changes: 2 additions & 3 deletions R/data_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ NULL
#' \url{http://www.wunderground.com/about/faq/US_cities.asp}
#' @keywords data
#'
NULL
"USAirportWeatherStations"

#' @title Data - International Weather Stations
#' @description This is a data frame of the 1602 stations in Weather Underground's
Expand All @@ -121,5 +121,4 @@ NULL
#' maintained by Greg Thompson of NCAR.
#' @keywords data
#'
NULL

"IntlWxStations"
7 changes: 7 additions & 0 deletions R/util_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ keepOnlyMinMax <- function(single_day_df,

}


data("IntlWxStations" , envir=environment())
data("USAirportWeatherStations", envir=environment())


#' Shows all the available Weather Data Columns
#'
#' Displays all the columns that are available in the website, for the given
Expand Down Expand Up @@ -137,8 +142,10 @@ showAvailableColumns<- function(station_id,
#'@export
getStationCode <- function(stationName, region=NULL){


stn2 <- NULL; us_stns <- NULL
intl_stn2 <- NULL; i_stns <- NULL

if(!is.null(region)){
region_matches <- grep(pattern=region,
USAirportWeatherStations$State,
Expand Down
4 changes: 4 additions & 0 deletions R/validity_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ validYear <- function(year){
if(year <= 0){
return(0)
}
if(year <= 1970){
warning("\nWARNING: The year", year, "may not have any data.")
}

if(year > current_year){
warning("\nThe year cannot be greater than current year.")
return(0)
Expand Down
90 changes: 86 additions & 4 deletions R/wrapper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,11 @@ getWeatherForDate <- function(station_id,




#checkSummarizedDataAvailability("KBUF", "2012-12-12", end_date=NULL)

#' Get weather data for one full year
#'
#' @description Function will return a data frame with all the records
#' for a given station_id and year. If the current year is supplied,
#' it will returns records until the current Sys.Date() ("today")
#' it will return records until the current Sys.Date() ("today")
#'
#' @details Note that this function is a light wrapper for getWeatherForDate
#' with the two end dates being Jan-01 and Dec-31 of the given year.
Expand Down Expand Up @@ -599,3 +596,88 @@ getTemperatureForDate <- function(station_id,
opt_write_to_file)

}



#' @title For Multiple Years, fetch the weather data for a station
#'
#' @description Function will return a data frame with all the records
#' for a given station_id for all the years requested. If the current year is supplied,
#' it will return records until the current Sys.Date() ("today").
#' This function will return a (fairly large) data frame. If you are going
#' to be using this data for future analysis, you can store the results in a CSV file
#' by setting \code{opt_write_to_file} to be TRUE
#'
#' @details Note that this function is a light wrapper for getWeatherForYear
#'
#' @param station_id is a valid Weather Station ID
#' (example: "BUF", "ORD", "VABB" for Mumbai).
#' Valid Weather Station "id" values: "KFLMIAMI75" or "IMOSCOWO2" You can look these up
#' at wunderground.com. You can get station_id's for a given location
#' by calling \code{getStationCode()}
#' @param start_year is a valid year in the past (numeric, YYYY format)
#' @param end_year is a valid year in the past (numeric, YYYY format)
#' @param station_type = "airportCode" (3 or 4 letter airport code) or "ID" (Wx call Sign)
#' @param opt_detailed Boolen flag to indicate if detailed records for the station are desired.
#' (default FALSE). By default only one records per date is returned.
#' @param opt_write_to_file If TRUE, the resulting dataframe will be stored in a CSV file.
#' Default is FALSE
#' @references For a list of valid Weather Stations, try this format
#' \url{http://www.wunderground.com/weatherstation/ListStations.asp?selectedCountry=United+States}
#' and replace with your country of interest
#' @return A data frame with each row containing: \itemize{
#' \item Date and Time stamp (for each date specified)
#' \item Temperature and/or other weather columns sought
#' }
#'@examples
#'\dontrun{
#' dat <- getWeatherForMultipleYears("SFO", 2013, 2017)
#'
#' # If opt_detailed is turned on, you will get a large data frame
#' wx_SF <- getWeatherForMultipleYears("SIN", 2014, 2017, opt_detailed=TRUE)
#'}
#' @export
getWeatherForMultipleYears <- function(station_id,
start_year,
end_year,
station_type="airportCode",
opt_detailed=FALSE,
opt_write_to_file=FALSE){


if(!validYear(start_year)){ #check if year is valid
warning("Start Year argument is invalid. Please provide a valid 4-digit
year (numeric)")
return(NULL)
}

if(!validYear(end_year)){ #check if year is valid
warning("End Year argument is invalid. Please provide a valid 4-digit
year (numeric)")
return(NULL)
}

if(start_year>end_year){ #illegal time duration
warning("Start Year cannot be after End Year. Please make sure that \
the end year is after start year.")
return(NULL)
}

num_years <- end_year - start_year

multi_year <- vector("list", num_years)
for(year in start_year:end_year){
multi_year[[year]] <- getWeatherForYear(station_id,
year,
station_type=station_type,
opt_detailed=opt_detailed,
opt_write_to_file = opt_write_to_file)

}

#flatted the List into a data frame
multi_year_df <- do.call(rbind, multi_year)
return(multi_year_df)

}

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ If you want to perform weather Analysis, but don't wish to be bothered with scra
The main page for weatherData (with explanations and Examples) can be found
at [http://ram-n.github.io/weatherData/](http://ram-n.github.io/weatherData/)

### Shiny App

WeatherCompare is [a Shiny App](http://spark.rstudio.com/ram/WeatherCompare/) that uses the data brought over by weatherData and then summarized in various ways

# Install

Expand All @@ -28,8 +25,7 @@ Load the library
library(weatherData)
```

Windows users must also first install
[Rtools](http://cran.rstudio.com/bin/windows/Rtools/).
Windows users may also need to first install *Rtools* from CRAN. (Look in bin/windows)

## Suggestions

Expand Down
1 change: 1 addition & 0 deletions man/IntlWxStations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/USAirportWeatherStations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions man/getWeatherForMultipleYears.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/getWeatherForYear.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/weatherData-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The package has functions that can fetch weather data.
\tabular{ll}{
Package: \tab weatherData\cr
Type: \tab Package\cr
Version: \tab 0.4\cr
Date: \tab 2014-04-29\cr
Version: \tab 0.5.0\cr
Date: \tab 2017-06-05\cr
License: \tab GPL\cr
}
These functions don't use APIs. They rely on reading URL's instead.
Expand Down

0 comments on commit be0e6af

Please sign in to comment.