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

issue warning on empty return set #9

Open
SymbolixAU opened this issue Jun 11, 2016 · 3 comments
Open

issue warning on empty return set #9

SymbolixAU opened this issue Jun 11, 2016 · 3 comments

Comments

@SymbolixAU
Copy link
Collaborator

No description provided.

@jonocarroll
Copy link

jonocarroll commented Jun 20, 2016

For a ZERO_RESULTS return, try

> google_directions(origin = "Adelaide, South Australia", destination = "New York, New York", key="")
$available_travel_modes
[1] "DRIVING"   "BICYCLING" "WALKING"  

$geocoded_waypoints
  geocoder_status                    place_id                                types
1              OK ChIJP7Mmxcc1t2oRQMaOYlQ2AwQ colloquial_area, locality, political
2              OK ChIJOwg_06VPwokRYv534QaPC8g                  locality, political

$routes
list()

$status
[1] "ZERO_RESULTS"

It's not necessarily your package's duty to do this checking, but it could. It would be good to document the returned list (when simplify=TRUE) and mention that there's a $status that is checked against (and potential values, likely listed in the API docs). It's particularly friendly to do so given that there's potential for an empty list() to be returned (the fun of lapply in jsonlite::simplify).

Handling of this case (and a successful one) should also appear in your automated package testing.

@SymbolixAU
Copy link
Collaborator Author

SymbolixAU commented Jun 20, 2016

The problem with testing actual API calls is I would have to expose my API key (unless you know of another way?)

@jonocarroll
Copy link

jonocarroll commented Jun 20, 2016

I usually save the key in a hidden file on my local drive outside of the git scope (add to .gitignore just in case) then read it in to the field.

 APIkey <- c(read.dcf("~/.googleAPI", fields = c("GOOGLE_API_KEY")))

 google_directions(origin      = ltrip[[1]],
                   destination = ltrip[[length(ltrip)]],
                   mode        = "bicycling",
                   waypoints   = ltrip,
                   key         = APIkey)

I can adapt a setup_google() function I've already got somewhere if you like. It can be run at the start of API calling functions and will ensure that the session is authenticated before continuing, otherwise prompt for such.

I've made the mistake of committing a key before; don't do that.

You can do the function testing locally with this option and not epose your key. Refer to the Skipping a test section of http://r-pkgs.had.co.nz/tests.html to see how to not require this when testing externally. Also, skip_on_cran().

@SymbolixAU SymbolixAU modified the milestones: 1.2.0, 2.8 Sep 21, 2018
@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant