Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions R/RSocrata.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,19 @@ read.socrata <- function(url, app_token = NULL, email = NULL, password = NULL,
# PAGE through data and combine
# if user limit is provided do not page
# if no limit $provided, loop until all data is paged
while (nrow(page) > 0 & !limitProvided) {
query <- paste(validUrl, if(is.null(parsedUrl$query)) {'?'} else {"&"},
'$limit=50000&$offset=', nrow(result), sep='')
response <- getResponse(query, email, password)
page <- getContentAsDataFrame(response)
result <- rbind.fill(result, page) # accumulate
}

# If an offset has been used, and limit has not been provided, skip the paging and return a message
if(!is.null(parsedUrl$query$`$offset`) & !limitProvided){
message(paste('Returning results from offset of', format(parsedUrl$query$`$offset`, big.mark=",")))
} else {
while (nrow(page) > 0 & !limitProvided) {
query <- paste(validUrl, if(is.null(parsedUrl$query)) {'?'} else {"&"},
'$limit=50000&$offset=', nrow(result), sep='')
response <- getResponse(query, email, password)
page <- getContentAsDataFrame(response)
result <- rbind.fill(result, page) # accumulate
}
}
if (is.null(dataTypes)) {
warning("Dates and currency fields will be converted to character")
} else {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,14 @@ test_that("getContentAsDataFrame does not get caught in infinite loop", {
expect_equal("data.frame", class(df), label="class")
})


context("User-defined offset")

test_that("User can specify offset", {

rows_hist = 108000 # rows of data previously read
df <- read.socrata(url = paste0("https://data.cambridgema.gov/resource/gxzm-dpwp.csv?$offset=", rows_hist))

expect_equal("data.frame", class(df), label="class")
})