-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from quandl/AP-1699/datatables
Ap 1699/datatables
- Loading branch information
Showing
14 changed files
with
336 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
language: r | ||
r: | ||
- oldrel | ||
- release | ||
cache: packages | ||
# Be strict when checking our package | ||
warnings_are_errors: true | ||
sudo: required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
YEAR: 2015 | ||
YEAR: 2016 | ||
COPYRIGHT HOLDER: Quandl Inc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#' Retrieves Data from the Quandl Datatable endpoint | ||
#' | ||
#' @details Set your \code{api_key} with \code{Quandl.api_key} function. For instructions on finding your api key go to \url{https://www.quandl.com/account/api} | ||
#' | ||
#' @param code Datatable code on Quandl specified as a string. | ||
#' @param paginate When set to TRUE, fetches up to 1,000,000 rows of data | ||
#' @param ... Additional named values that are interpreted as Quandl API parameters. | ||
#' @return Returns a data.frame. | ||
#' @seealso \code{\link{Quandl.api_key}} | ||
#' @examples \dontrun{ | ||
#' Quandl.datatable('ZACKS/FC', paginate=TRUE) | ||
#' } | ||
#' @export | ||
Quandl.datatable <- function(code, paginate=FALSE, ...) { | ||
path <- paste0("datatables/", code) | ||
params <- list(...) | ||
|
||
# make request for first page of data | ||
json <- do.call(quandl.api, c(path=path, params)) | ||
datatable <- json$datatable | ||
data <- datatable$data | ||
# contains a list of names and corresponding types | ||
columns <- datatable$columns | ||
next_cursor_id <- json$meta$next_cursor_id | ||
df <- as.data.frame(data, stringsAsFactors=FALSE) | ||
|
||
# continue to make requests for data if paginate=TRUE and there is data | ||
while (isTRUE(paginate) && !is.null(next_cursor_id)) { | ||
params['qopts.cursor_id'] <- next_cursor_id | ||
json <- do.call(quandl.api, c(path=path, params)) | ||
df_page <- as.data.frame(json$datatable$data, stringsAsFactors=FALSE) | ||
df <- rbind(df, df_page) | ||
next_cursor_id <- json$meta$next_cursor_id | ||
|
||
# only fetch a maximum of 1,000,000 rows | ||
if (nrow(df) >= quandl.datatable.max_rows() && !is.null(next_cursor_id)) { | ||
warning(paste("This call returns a larger amount of data than Quandl.datatable() allows.", | ||
"Please view our documentation on developer methods to request more data.", | ||
"https://github.com/quandl/quandl-r/blob/master/README.md#datatables"), call. = FALSE) | ||
break | ||
} | ||
} | ||
|
||
if (!isTRUE(paginate) && !is.null(next_cursor_id)) { | ||
warning(paste("This call returns more data. To request more pages, please set paginate=TRUE", | ||
"in your Quandl.datatable() call. For more information see our documentation:", | ||
"https://github.com/quandl/quandl-r/blob/master/README.md#datatables"), call. = FALSE) | ||
} | ||
|
||
names(df) <- columns[,1] | ||
df <- quandl.datatable.convert_df_columns(df, columns[,2]) | ||
|
||
return(df) | ||
} | ||
|
||
quandl.datatable.convert_df_columns <- function(df, column_types) { | ||
if (length(column_types) <= 0) { | ||
return(df) | ||
} | ||
column_types <- tolower(column_types) | ||
for(i in 1:length(column_types)) { | ||
if (grepl("^float|^bigdecimal|^integer", column_types[i])) { | ||
df[,i] <- as.numeric(df[,i]) | ||
} else if (grepl("^date", column_types[i])) { | ||
df[,i] <- as.Date(df[,i]) | ||
} | ||
} | ||
return(df) | ||
} | ||
|
||
quandl.datatable.max_rows <- function() { | ||
return(1000000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/Quandldatatable.R | ||
\name{Quandl.datatable} | ||
\alias{Quandl.datatable} | ||
\title{Retrieves Data from the Quandl Datatable endpoint} | ||
\usage{ | ||
Quandl.datatable(code, paginate = FALSE, ...) | ||
} | ||
\arguments{ | ||
\item{code}{Datatable code on Quandl specified as a string.} | ||
|
||
\item{paginate}{When set to TRUE, fetches up to 1,000,000 rows of data} | ||
|
||
\item{...}{Additional named values that are interpreted as Quandl API parameters.} | ||
} | ||
\value{ | ||
Returns a data.frame. | ||
} | ||
\description{ | ||
Retrieves Data from the Quandl Datatable endpoint | ||
} | ||
\details{ | ||
Set your \code{api_key} with \code{Quandl.api_key} function. For instructions on finding your api key go to \url{https://www.quandl.com/account/api} | ||
} | ||
\examples{ | ||
\dontrun{ | ||
Quandl.datatable('ZACKS/FC', paginate=TRUE) | ||
} | ||
} | ||
\seealso{ | ||
\code{\link{Quandl.api_key}} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.