View on GitHub


An R package that fetches Weather data from websites

Download this project as a .zip file Download this project as a tar.gz file

weatherData is a collection of functions that will fetch weather (Temperature, Pressure, Humidity etc.) data from the Web for you as clean data frame.

Using WeatherData

If you want to perform weather Analysis, but don't wish to do the data scraping yourself, you can consider using weatherData. Given a few parameters, it has functions that return the available data in a time-stamped data frame that is easy to work with.

Two Installation Options

You can install the version from CRAN, or you can try out the version hosted in Github. Github has the newer version, which is in development. This is where I try out the newer functions.

Option 1: Install from CRAN

Install and Load the library


Option 2: Install from Github

The latest version of weatherData is on Github. (Note that this is the development version, and is usually ahead of what's on CRAN.) To install the development version of weatherData from github, use the devtools package.


Once the package has installed, load the library


Note: Windows users must also first install Rtools.

Basic Usage: Quickstart

If you want to get started using the functions in the package right away, you can do so.

Quickstart Example 1. Start by getting the temperature data for a Location of interest for a particular date.

 getWeatherForDate("SEA", "2014-05-05")

Quickstart Example 1a. If you want detailed data (meaning, more columns besides Temperature):

 getWeatherForDate("SEA", "2014-05-05", opt_detailed=TRUE)

Quickstart Example 1b. If you want detailed data for a range of dates instead of for a single date, just specify a start date and end date:

 getWeatherForDate("SEA", "2014-04-01", end_date="2014-04-30")
 #This will fetch a dataframe of temperature data for the month of April.

Quickstart Example 2. Just get me everything for a whole year for a Location of interest.

 dfw_wx <- getWeatherForYear("DFW", 2013)

This is a just a very small sample of the functions. There are also a number of 'helper functions' to make life a little easier.

Using the package: Typical Workflow

Typically, in order to analyze the available weather data, you will need to decide on four parameters:

  1. Location. (Which city, zipcode or weather station are you interested in)
  2. Time Interval (Is this for 1 day, a sequence of dates, or a whole year or more)
  3. Level of Detail: Is one record per day adequate? (If so, use summarized) If not, specify the opt_detailed option.
  4. Which of the available columns are you interested in? (Temperature, Pressure, Wind, Humidity or all the available ones.)

In all the examples, it is assumed that you have loaded the library. You can do so by typing library(weatherData).

Step 1:

Find the station id for the location(s) that you are interested in. If you know the airport code (3 letters) you can try that. Once you have the station_id and the date ranges, it is a simple matter to fetch the data.

Details around finding the weather station ID's can be found here

Step 2:

Set the date range: start_date="YYYY-MM-DD" and end_date="YYYY-MM-DD" If you need data for just one day, then end_date doesn't have to be specified.

Step 3:

If the default level of detail is sufficient, call one of the getWeatherData() functions, and assign the data frame being returned to it.

wx_df <- getWeatherForDate("SAN", "2011-08-26")

Detailed Examples

A few more Detailed Examples of the functions in weatherData can be found in these pages.

Frequently Asked Questions

Built-in Datasets

The package comes with a few pre-loaded datasets and those are available for trying out some basic analysis right away. More details about what is included and what each of those datasets contains can be found here. That page also includes some sample code for using one of the datasets, Mumbai2013

weatherData Demo Application

WeatherCompare is a Shiny App that uses the data brought over by weatherData and then summarized in various ways.

Articles about weatherData

There have been a few articles written about the functions in this package. They might be useful to get a feel for use cases.

Joe Rickert of Revolution Analytics has written a blog post with a sample script that uses weatherData. Do check it out.

Angela Hey, a tech blogger for the Mountain View Voice wrote an article about analyzing data with R, and used weatherData functions for her examples.

Here's a presentation about the features in weatherData that are new to version 0.4. It was part of a short lightning I gave for the BARUG group. And here's Joe Rickert's summary of the talks.


The weatherData package has benefited immensely from the suggestions of quite a number of weather analysts. Their feedback, suggestions and bug reports have helped immensely. Detailed credits for their contributions can be found here.

Ram Narasimhan