weatherData is a collection of functions that will fetch weather (Temperature, Pressure, Humidity etc.) data from the Web for you as clean data frame.
Several examples can be found in the main page
More Examples
How to find the station_id for a Location
Let's say that we want to search for weather in Buffalo. But we are interested in Buffalo, WY, not Buffalo,NY.
getStationCode("Buffalo")
#If we want to be more specific about the location of interest
#We can specify the additional parameter region
getStationCode("Buffalo", region="WY")
This function will return a record containing matches to a given station name, and the 4 letter code can then be used in the arguments to other functions such as getWeatherForDate()
> getStationCode("Buffalo", region="WY")
[[1]]
Station State airportCode
1588 Buffalo WY KBYG
So, we can see that the 4-letter airportCode that we are interested in is KBYG
Check if Data is Available
In general, it is a good idea to first check if data is available for our location and dates of interest. Throughout the package, we make a distinction between a Date and a Date Range
checkDataAvailability("KBYG", "2011-01-02") #checking for a single date
checkDataAvailabilityForDateRange("SFO", "2010-10-29", "2013-01-12") #checking for a date range
The first command searches for Data Availability (in Weather Underground) for the date specified. The second command above will see if weather data is available for the Airport supplied ("SFO") for the two end dates supplied: for the 20th Oct 2010 and for Jan 12th 2013 in this case.
These commands are useful for a quick check, before invoking getDateRangeWeather
Getting the current temperature of a Location
getCurrentTemperature("PIT")
If you are writing functions that use the current (latest) temperature for any location, you can try using the
getCurrentTemperature function. This function will get the latest recorded Temperature for a give city or station. Any valid US Airport code or International 4-letter Airport Weather Code will usually work. For example "EGLL" for London, UK. This function returns a NULL if it is unable to fetch the temperature, so you can test for that using is.null().
Caution: This function uses the Sys.Date to learn today's date. So it might be a good idea to test it before including it in your script.
List of the different functions available in weatherData
Functions to Check if Data is available
checkDataAvailabilityCheck if WeatherUnderground has Data for given station and datecheckDataAvailabilityForDateRangeQuick Check to see if WeatherUnderground has Weather Data for given station for a range of datescheckSummarizedDataAvailabilityQuick Check to see if WeatherUnderground has Summarized Weather Data for given station for a custom range of dates
Helper Functions
showAvailableColumnsShows all the available Weather Data ColumnsgetStationCodeGets the Weather Station code for a location (in the US)getCurrentTemperatureGet the latest recorded temperature for a location
Core Functions that fetch Weather Data
getDetailedWeatherGets weather data for a single date (All records)getSummarizedWeatherGets daily summary weather data (One record per day)
Convenience Wrappers
getWeatherForDateGetting data for a range of datesgetWeatherForYearGet weather data for one full year
Built-in Datasets
There are also a number of data sets that come with the package. Be sure to check them out as well.