Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding limit and offset as params to read.socrata #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion R/RSocrata.R
Expand Up @@ -265,7 +265,7 @@ getSodaTypes <- function(response) {
#' @importFrom plyr rbind.fill
#' @export
read.socrata <- function(url, app_token = NULL, email = NULL, password = NULL,
stringsAsFactors = FALSE) {
stringsAsFactors = FALSE, limit = NULL, offset = NULL) {
validUrl <- validateUrl(url, app_token) # check url syntax, allow human-readable Socrata url
parsedUrl <- httr::parse_url(validUrl)
mimeType <- mime::guess_type(parsedUrl$path)
Expand All @@ -279,6 +279,14 @@ read.socrata <- function(url, app_token = NULL, email = NULL, password = NULL,
validUrl <- paste(validUrl, {'?'}, '$order=:id', sep='')
parsedUrl <- httr::parse_url(validUrl) # reparse because URL now has a query
}
if(!is.null(limit)){
validUrl <- paste(validUrl, '&', sprintf('$limit=%s',limit) , sep='')
parsedUrl <- httr::parse_url(validUrl) # reparse because URL now has a query
}
if(!is.null(offset)){
validUrl <- paste(validUrl, '&', sprintf('$offset=%s',offset) , sep='')
parsedUrl <- httr::parse_url(validUrl) # reparse because URL now has a query
}
if(!(mimeType %in% c('text/csv','application/json')))
stop("Error in read.socrata: ", mimeType, " not a supported data format.")
response <- getResponse(validUrl, email, password)
Expand Down