Skip to content

Commit

Permalink
fixed skip-test errors and updated vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Jun 10, 2016
1 parent d0ea66a commit ed8ce58
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 53 deletions.
2 changes: 1 addition & 1 deletion R/google_directions.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ google_directions <- function(origin,
language = NULL,
region = NULL,
key,
simplify = c(TRUE, FALSE)){
simplify = TRUE){

directions_data(base_url = "https://maps.googleapis.com/maps/api/directions/json?",
information_type = "directions",
Expand Down
2 changes: 1 addition & 1 deletion R/google_distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ google_distance <- function(origins,
language = NULL,
region = NULL,
key = NULL,
simplify = c(TRUE, FALSE)){
simplify = TRUE){

directions_data(base_url = "https://maps.googleapis.com/maps/api/distancematrix/json?",
information_type = "distance",
Expand Down
2 changes: 1 addition & 1 deletion R/google_elevation.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ google_elevation <- function(df_locations,
location_type = c("individual","path"),
samples = NULL,
key,
simplify = c(TRUE, FALSE)
simplify = TRUE
){

## check location
Expand Down
2 changes: 1 addition & 1 deletion R/google_geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ google_geocode <- function(address,
language = NULL,
region = NULL,
components = NULL,
simplify = c(TRUE, FALSE)){
simplify = TRUE){

## parameter check - key
if(is.null(key))
Expand Down
2 changes: 1 addition & 1 deletion R/google_reverse_geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ google_reverse_geocode <- function(location,
location_type = NULL,
language = NULL,
key,
simplify = c(TRUE, FALSE)){
simplify = TRUE){

## parameter check - key
if(is.null(key))
Expand Down
2 changes: 1 addition & 1 deletion R/google_timezone.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
google_timezone <- function(location,
timestamp = Sys.time(),
language = NULL,
simplify = c(TRUE, FALSE),
simplify = TRUE,
key
){

Expand Down
2 changes: 1 addition & 1 deletion R/googleway-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ directions_data <- function(base_url,
language = NULL,
region = NULL,
key,
simplify = c(TRUE, FALSE)){
simplify = TRUE){

## parameter check
if(is.null(key))
Expand Down
63 changes: 62 additions & 1 deletion man/google_directions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/google_distance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/google_elevation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/google_geocode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/google_reverse_geocode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/google_timezone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions tests/testthat/test-google_directions.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ test_that("google_directions returns data.frame", {
expect_equal(length(df[[1]]), 3)
})

test_that("incorrect mode throws error", {

expect_error(google_directions(origin = c(-37.8179746, 144.9668636),
destination = c(-37.81659, 144.9841),
mode = "non-mode",
key = "abc",
simplify = TRUE),
"'arg' should be one of \"driving\", \"walking\", \"bicycling\", \"transit\"")

})
# test_that("incorrect mode throws error", {
#
# expect_error(google_directions(origin = c(-37.8179746, 144.9668636),
# destination = c(-37.81659, 144.9841),
# mode = "non-mode",
# key = "abc",
# simplify = TRUE),
# "'arg' should be one of \"driving\", \"walking\", \"bicycling\", \"transit\"")
#
# })

test_that("incorrect simplify throws warning",{

Expand Down Expand Up @@ -116,6 +116,8 @@ test_that("map url is a single string",{

test_that("transit_mode issues warning when mode != transit",{

skip_api_key()

expect_warning(google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
Expand All @@ -130,6 +132,9 @@ test_that("transit_mode issues warning when mode != transit",{

test_that("warning when both arrival and departure times supplied", {

## skip this test
skip_api_key()

expect_warning(google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
Expand All @@ -139,7 +144,3 @@ test_that("warning when both arrival and departure times supplied", {

})





6 changes: 5 additions & 1 deletion tests/testthat/test-google_distances.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("Google distance")
context("Google distance")

## api keys are not included in the package
## and so can't be tested
Expand Down Expand Up @@ -96,6 +96,8 @@ test_that("map url is a single string",{

test_that("transit_mode issues warning when mode != transit",{

skip_api_key()

expect_warning(google_distance(origins = "Melbourne Airport, Australia",
destinations = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
Expand All @@ -110,6 +112,8 @@ test_that("transit_mode issues warning when mode != transit",{

test_that("warning when both arrival and departure times supplied", {

skip_api_key()

expect_warning(google_distance(origins = "Melbourne Airport, Australia",
destinations = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-google_elevation.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
context("Google elevation")

skip_api_key <- function() {
skip("key not available")
}

test_that("df_locations is a data.frame",{

Expand Down Expand Up @@ -39,7 +42,10 @@ test_that("df_locations only contains one of each lat/lon columns",{
"Multiple possible lat/lon columns detected. Only use one column for lat/latitude and one column for lon/longitude coordinates")
})

test_that("warning issued when samples == NULL", {
test_that("warning issued when samples is NULL", {

## skip this test
skip_api_key()

df <- data.frame(lat = c(-37.81659, -37.88950),
lon = c(144.9841, 144.9841))
Expand All @@ -50,13 +56,8 @@ test_that("warning issued when samples == NULL", {
key = "abc",
simplify = TRUE),
"samples has not been specified. 3 will be used")

})








1 change: 0 additions & 1 deletion tests/testthat/test-google_reverse_geocode.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
context("Google reverse_geocode")


test_that("incorrect location throws error",{

expect_error(google_reverse_geocode(location = "Flinders Street Station, Melbourne",
Expand Down
33 changes: 15 additions & 18 deletions vignettes/googleway-vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ The same query using the developers API generates the data in JSON

![Melbourne to Sydney JSON](./img/melbourne_to_sydney_json.png)

This result can be returned using the `google_directions()` function.

Note you can return the output as **JSON** or a **data.frame**.
This result can be returned using the `google_directions()` function. By default the result will be coerced to the simplest `R` structure possible using `jsonlite::fromJSON()`. If you would like the result in JSON set `simplify = FALSE`.

```
library(googleway)
Expand All @@ -54,7 +52,7 @@ df <- google_directions(origin = "Melbourne, Australia",
destination = "Sydney, Australia",
key = key,
mode = "driving",
output_format = "data.frame")
simplify = TRUE)
```

The data used to draw the route is the **overview_polyline**
Expand Down Expand Up @@ -97,8 +95,7 @@ df <- google_distance(origins = list(c("Melbourne Airport, Australia"),
c("MCG, Melbourne, Australia"),
c(-37.81659, 144.9841)),
destinations = c("Portsea, Melbourne, Australia"),
key = key,
output_format = "data.frame")
key = key)
head(df)
$destination_addresses
Expand Down Expand Up @@ -133,12 +130,12 @@ To access this API through googleway use the `google_elevation()` function.
Finding the elevation of 20 points between the MCG, Melbourne and the beach at Elwood, Melbourne

```
df <- google_elevation(df_locations = data.frame(lat = c(-37.81659, -37.88950),
lon = c(144.9841, 144.9841)),
location_type = "path",
samples = 20,
key = key,
output_format = "data.frame")
google_elevation(df_locations = data.frame(lat = c(-37.81659, -37.88950),
lon = c(144.9841, 144.9841)),
location_type = "path",
samples = 20,
key = key,
simplify = TRUE)
$results
elevation location.lat location.lng resolution
Expand Down Expand Up @@ -181,9 +178,9 @@ Finding the timezone of the MCG in Melbourne

```
google_timezone(location = c(-37.81659, 144.9841),
timestamp = as.POSIXct("2016-06-05"),
output_format = "JSON",
key = key)
timestamp = as.POSIXct("2016-06-05"),
key = key,
simplify = FALSE)
[1] "{"
[2] " \"dstOffset\" : 0,"
Expand Down Expand Up @@ -211,7 +208,7 @@ Finding the location details for Flinders Street Station, Melbourne
An unbound search for Flinders Street Station returns 6 options.
df <- google_geocode(address = "Flinders Street Station",
key = key,
output_format = "data.frame")
simplify = TRUE)
df$results$formatted_address
[1] "Flinders Street Railway Station, Flinders St, Melbourne VIC 3000, Australia"
Expand All @@ -229,7 +226,7 @@ bounds <- list(c(-37.81962,144.9657),
df <- google_geocode(address = "Flinders Street Station",
bounds = bounds,
key = key,
output_format = "data.frame")
simplify = TRUE)
df$results$formatted_address
[1] "Flinders Street Railway Station, Flinders St, Melbourne VIC 3000, Australia"
Expand All @@ -256,7 +253,7 @@ df <- google_reverse_geocode(location = c(-37.81659, 144.9841),
result_type = c("street_address", "postal_code"),
location_type = "rooftop",
key = key,
output_format = "data.frame")
simplify = TRUE)
df$results$address_components
[[1]]
Expand Down

0 comments on commit ed8ce58

Please sign in to comment.