Using Quandl from R
Quandl's free R app allows you to access Quandl data directly from within R.
If you haven't already read Quandl's API documentation, we recommend you do so before proceeding.
Quandl is available within the R console as a free package on CRAN. To download and install from CRAN, simply type:
Sometimes a more recent version of the Quandl package may be available on Github. (CRAN packages often update with a lag). To download and install the latest version from Github, enter this code snippet:
install.packages("devtools") library(devtools) install_github('R-package','quandl') library(Quandl)
To make more than 50 calls a day, you will need an authentication token. You can find your auth_token under the API tab on your account page.
Once you have your auth_token, then after the Quandl library is loaded type this (including the quotes):
Now when you call the Quandl function in R, it will automatically use your auth_token to connect with the Quandl API.
Api usage is currently unlimited, but throttled. For more information see our api page.
Just pick a dataset and enter its Quandl code, like this:
mydata = Quandl("FRED/GDP")
The Quandl package is able to return data in 4 very usable formats: data frame ("raw"), ts ("ts"), zoo ("zoo") and xts ("xts"). The default is "raw". Here's how to get your data in ts format:
mytimeseries = Quandl("NSE/OIL", type="ts")
You can get multiple datasets in one call by passing an array of Quandl codes, like this:
mydata = Quandl(c("NSE/OIL.4","WIKI/AAPL.1"))
This grabs the 4th column of dataset NSE/OIL and the 1st column of dataset WIKI/AAPL, and returns them in a single call.
We are currently moving towards having all site traffic over https. This is causing some issues within the R package. If you are having issues due to ssl or https please let us know. Until these issues are resolved you can switch back to http traffic by using the latest version on github and typing:
library(Quandl) assignInNamespace('Quandl.host', 'http://www.quandl.com/api', 'Quandl')
Just like the basic API, the R package offers various ways to manipulate or transform the data prior to download:
Specific Date Range:
mydata = Quandl("NSE/OIL", start_date="yyyy-mm-dd", end_date="yyyy-mm-dd")
mydata = Quandl("NSE/OIL", collapse="annual")
mydata = Quandl("NSE/OIL", transformation="rdiff")
(These transformations are documented more fully on our API page.)
For further transformations, you might find our Cheat Sheet on time series analysis using R and Quandl useful.
You can search Quandl for datasets from within the R console. Here is an example search:
Quandl.search(query = "crude oil", page = 2, source = "DOE", silent = TRUE)
The only mandatory parameter is "query". "page" specifies which page of search results you wish to see (default=1). "source" specifies that you want to search within a particular data source (default=all data sources). "silent" specifies whether or not you want to see the first 3 results on the console.
We have created a simple cheat sheet for R users; it covers basic R syntax, vector and matrix operations, time series manipulation, plotting, and Quandl data access. You can download the cheat sheet here.
Please do email us with suggestions, feedback, bug reports, feature requests or code contributions. Thank you for your support!
Our thanks to Gergely Daróczi, Paul Gilbert and Hideyoshi Maeda for their help with this package.