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

v1.7.4 #149

Merged
merged 9 commits into from
Dec 12, 2017
Merged

v1.7.4 #149

merged 9 commits into from
Dec 12, 2017

Conversation

tomschenkjr
Copy link
Contributor

This version fixes a bug raised by CRAN and introduces two very minor features. @nicklucius and @geneorama - please review the package of changes and add your approval or any comments.

New features:

Bug fixes:

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 96.859% when pulling 9bbbeae on hotfix1.7.4 into 2c7d866 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 96.859% when pulling 9bbbeae on hotfix1.7.4 into 2c7d866 on master.

@geneorama
Copy link
Member

I noticed that every time fetch_user_agent is called, it's called within httr::user_agent, like this: httr::user_agent(fetch_user_agent()).

Would it make more sense to bundle the httr::user_agent inside the fetch function?

R/RSocrata.R Outdated
#' @author Hugh J. Devlin, Ph. D. \email{Hugh.Devlin@@cityofchicago.org}
#' @noRd
getResponse <- function(url, email = NULL, password = NULL) {

if(is.null(email) && is.null(password)){
response <- httr::GET(url)
response <- httr::GET(url, user_agent(fetch_user_agent()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no httr:: in front of user_agent
(but this isn't an error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, agree with this. Will make the change (though strikes me as an odd style, it's semantically appropriate).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I had never suggested the namespace thing because we don't consistently follow it (there are two places outside the review that don't have it). So, we get the downside of reduced readability without the benefit of having all foreign calls fully specified.

So I have mixed feelings about even making this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense, the use of user_agent is odd because it--in my mind--only makes sense in the context of GET, POST, PUT, etc instead of a standalone function. It's a good idea to call the namespace (also, I think reduces the chance of us being chided by CRAN).

R/RSocrata.R Outdated
#' @export
ls.socrata <- function(url) {
url <- as.character(url)
parsedUrl <- httr::parse_url(url)
if(is.null(parsedUrl$scheme) | is.null(parsedUrl$hostname))
stop(url, " does not appear to be a valid URL.")
parsedUrl$path <- "data.json"
data_dot_json <- jsonlite::fromJSON(httr::build_url(parsedUrl))
#Download data
response <- httr::GET(httr::build_url(parsedUrl), user_agent(fetch_user_agent()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no httr:: in front of user_agent
(but this isn't an error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'll make the change.

"R/", rVersion,
")"
)
return(header)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the call to httr::user_agent here, but there is no error as it stands.
e.g. something like this:

result <- httr::user_agent(header)
return(result)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little less inclined for this change. If we make the change, the call from GET would be:

GET( url, fetch_user_agent() )

But, I think I prefer the literal call-out in the current method:

GET( url, user_agent( fetch_user_agent() ) )

@@ -419,6 +419,17 @@ test_that("incorrect API Query Human Readable", {
expect_equal(9, ncol(df), label="columns")
})

context("URL suffixes from Socrata are handled")

test_that("Handle /data suffix", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're only testing the ability to correctly parse URLs that end in data or data/ I would make the check just check that rather than checking the entire download process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to agree. Can be a later touch-up.

/cc @nicklucius

na_time_rows <- df[is.na(df$TARGET_DT), ]
expect_equal(33, length(na_time_rows), label="rows with missing TARGET_DT dates")
})
# test_that("Read data with missing dates", { # See issue #24 & #27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we could

  • comment this to explain that the Boston data set we were using is no longer available
  • work to find a another similar test?

However this is fine as it stands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point, we should make a reference to the issue instead of just commenting-out. Will make the change.

Copy link
Member

@geneorama geneorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found no problems that would prevent merging this branch into master, but I have made some comments / observations.

@tomschenkjr
Copy link
Contributor Author

tomschenkjr commented Dec 12, 2017 via email

@geneorama
Copy link
Member

I mean that I think you could return the header after you process it with user agent. So, each subsequent call to the function would be shorter and less nested. So, in the fetcher you'd have this at the end: return(httr::user_agent(header))

Right now each call looks like this: user_agent(fetch_user_agent())

With the proposed change each call would look like this: fetch_user_agent()

So, the fetch function would return the actual httr request object (which is a list of class "request") rather than a character string which needs to be converted to a request object each time.

Based on feedback from @geneorama, have included the `httr::` prefix to all `user_agent()` calls.

Added clarifying comments related to #137 so our future-selves can be reminded of turning on the test again.
@coveralls
Copy link

coveralls commented Dec 12, 2017

Coverage Status

Coverage increased (+0.5%) to 96.859% when pulling 53c4bf4 on hotfix1.7.4 into 2c7d866 on master.

@tomschenkjr
Copy link
Contributor Author

I've made some changed based on Gene's feedback. Merging into master for now. We can make some corrections before we submit to CRAN, which I plan to do on Friday.

@tomschenkjr tomschenkjr merged commit cff3e5f into master Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants