Skip to content

Commit

Permalink
Merge 98be365 into fa923de
Browse files Browse the repository at this point in the history
  • Loading branch information
geneorama committed Sep 1, 2016
2 parents fa923de + 98be365 commit 4d11bf6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Description: Provides easier interaction with
format and manages throttling by 'Socrata'.
Users can upload data to Socrata portals directly
from R.
Version: 1.7.1-12
Version: 1.7.1-13
Date: 2016-03-13
Author: Hugh Devlin, Ph. D., Tom Schenk, Jr., and John Malc
Maintainer: "Tom Schenk Jr." <developers@cityofchicago.org>
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ Bug fixes:
* Fixes bug where dates are incorrectly read when first date is a blank ([#68](https://github.com/Chicago/RSocrata/issues/68))
* Dates are now handled using `POSIXct` instead of `POSIXlt` ([#8](https://github.com/Chicago/RSocrata/issues/8))
* Added additional unit testing ([#28](https://github.com/Chicago/RSocrata/issues/68))
* Artifacts from Appveyor CI can now be directly submitted to CRAN ([#77](https://github.com/Chicago/RSocrata/issues/77))
* Artifacts from Appveyor CI can now be directly submitted to CRAN ([#77](https://github.com/Chicago/RSocrata/issues/77))
* Fixed issue where JSON may occasionally come back with a final NULL that is not "[]" (in this example it was "[]\n"). This caused `getDataFrame` to get stuckin an infinite loop while waiting for "[]". Thank you @kevinsmgov for documenting this bug in issue ([#96](https://github.com/Chicago/RSocrata/issues/96))

3 changes: 1 addition & 2 deletions R/RSocrata.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ getContentAsDataFrame <- function(response) {
encoding = "utf-8")),
stringsAsFactors = FALSE), # automatic parsing
'application/json' =
if(httr::content(response,
as = 'text') == "[ ]") # empty json?
if(length(httr::content(response)) == 0) # empty json?
data.frame() # empty data frame
else
data.frame(t(sapply(httr::content(response), unlist)),
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,26 @@ test_that("fully replace a dataset", {
expect_equal(df_in$x, as.numeric(df_out$x), label = "x values")
expect_equal(df_in$y, as.numeric(df_out$y), label = "y values")
})


context("getContentAsDataFrame")

test_that("getContentAsDataFrame does not get caught in infinite loop", {

## This is the original url suggested, but it causes the rbind issue
# u <- paste0("https://data.smgov.net/resource/xx64-wi4x.json?$",
# "select=incident_number,incident_date,call_type,received_time,",
# "cleared_time,census_tract_2010_geoid",
# "&$where=incident_date=%272016-08-21%27")

## This request has been modified to avoid the rbind issue
u <- paste0("https://data.smgov.net/resource/xx64-wi4x.json?$",
"select=incident_number,incident_date,call_type,received_time,",
"cleared_time,census_tract_2010_geoid",
"&$where=incident_date=%272016-08-27%27%20and%20",
"census_tract_2010_geoid%20is%20not%20null")
library(RSocrata)
df <- read.socrata(u)
expect_equal("data.frame", class(df), label="class")
})

0 comments on commit 4d11bf6

Please sign in to comment.