Skip to content

Commit

Permalink
departure and arrival times since 1970 - for SymbolixAU#170
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Aug 1, 2018
1 parent 0e00d8d commit d5490c5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 83 deletions.
9 changes: 5 additions & 4 deletions R/google_directions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#' @param destination destination location as either a one or two column data.frame, a
#' list of unnamed elements, each element is either a numeric vector of lat/lon
#' coordinates, an address string or place_id, or a vector of a pair of lat / lon coordinates
#' @param mode string. One of 'driving', 'walking', 'bicycling' or 'transit'.
#' @param departure_time \code{POSIXct}. Specifies the desired time of departure.
#' Must be in the future (i.e. greater than \code{sys.time()}). If no value
#' @param mode \code{string} One of 'driving', 'walking', 'bicycling' or 'transit'.
#' @param departure_time a \code{POSIXct} time since 1st January 1970.
#' Specifies the desired time of departure. If no value
#' is specified it defaults to \code{Sys.time()}
#' @param arrival_time \code{POSIXct}. Specifies the desired time of arrival. Note you
#' @param arrival_time a \code{POSIXct} time since 1st January 1970.
#' Specifies the desired time of arrival. Note you
#' can only specify one of \code{arrival_time} or \code{departure_time}, not both.
#' If both are supplied, \code{departure_time} will be used.
#' @param waypoints list of waypoints, expressed as either \code{vectors} of
Expand Down
30 changes: 1 addition & 29 deletions R/google_distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,10 @@
#' and time for a matrix of origins and destinations, based on the recommended
#' route between start and end points.
#'
#' @param origins Origin locations as either a one or two column data.frame, a
#' list of unnamed elements, each element is either a numeric vector of lat/lon
#' coordinates, an address string or a place_id, or a vector of a pair of lat / lon coordinates
#' @param destinations destination locations as either a one or two column data.frame, a
#' list of unnamed elements, each element is either a numeric vector of lat/lon
#' coordinates, an address string or place_id, or a vector of a pair of lat / lon coordinates
#' @param mode \code{string} One of 'driving', 'walking', 'bicycling' or 'transit'.
#' @param departure_time \code{POSIXct}. Specifies the desired time of departure. Must
#' be in the future (i.e. greater than \code{sys.time()}). If no value is specified
#' it defaults to \code{Sys.time()}
#' @param arrival_time \code{POSIXct}. Specifies teh desired time of arrival. Note you can
#' only specify one of \code{arrival_time} or \code{departure_time}, not both.
#' If both are supplied, \code{departure_time} will be used.
#' @param avoid \code{character} vector stating which features should be avoided.
#' One of 'tolls', 'highways', 'ferries' or 'indoor'
#' @param units \code{string} metric or imperial. Note: Only affects the text displayed
#' within the distance field. The values are always in metric
#' @param traffic_model \code{string}. One of 'best_guess', 'pessimistic' or 'optimistic'.
#' Only valid with a departure time
#' @param transit_mode \code{vector} of strings, either 'bus', 'subway', 'train', 'tram' or 'rail'.
#' Only vaid where \code{mode = 'transit'}. Note that 'rail' is equivalent to
#' \code{transit_mode=c("train", "tram", "subway")}
#' @inheritParams google_directions
#' @param transit_routing_preference \code{vector} strings - one of 'less_walking' and
#' 'fewer_transfers'. specifies preferences for transit routes. Only valid for
#' transit directions.
#' @param language \code{string}. Specifies the language in which to return the results.
#' See the list of supported languages: \url{https://developers.google.com/maps/faq#using-google-maps-apis}
#' If no langauge is supplied, the service will attempt to use the language of
#' the domain from which the request was sent
#' @param key \code{string}. A valid Google Developers Distance API key
#' @param simplify \code{logical} - TRUE indicates the returned JSON will be coerced into a list. FALSE indicates the returend JSON will be returned as a string
#' @param curl_proxy a curl proxy object
#' @return Either list or JSON string of the distance between origins and destinations
#'
#' @inheritSection google_geocode API use and limits
Expand Down
6 changes: 3 additions & 3 deletions R/parameter_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ validateDepartureTime <- function(departure_time){

checkPosix(departure_time)

if(departure_time < Sys.time()){
stop("departure_time must not be in the past")
}
# if(departure_time < Sys.time()){
# stop("departure_time must not be in the past")
# }

return(departure_time)
}
Expand Down
9 changes: 5 additions & 4 deletions man/google_directions.Rd

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

37 changes: 15 additions & 22 deletions man/google_distance.Rd

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

22 changes: 11 additions & 11 deletions tests/testthat/test-google_directions.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ test_that("Avoid is a valid type", {

})

test_that("Departure time is not in the past",{

expect_error(
google_directions(origin = c(-37.8179746, 144.9668636),
destination = c(-37.81659, 144.9841),
departure_time = as.POSIXct("2015-01-01"),
key = "abc",
simplify = TRUE)
)

})
# test_that("Departure time is not in the past",{
#
# expect_error(
# google_directions(origin = c(-37.8179746, 144.9668636),
# destination = c(-37.81659, 144.9841),
# departure_time = as.POSIXct("2015-01-01"),
# key = "abc",
# simplify = TRUE)
# )
#
# })

test_that("waypoints only valid for certain modes",{

Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-google_distances.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ test_that("Avoid is a valid type", {
"avoid can only include tolls, highways, ferries or indoor")
})

test_that("Departure time is not in the past",{

expect_error(google_distance(origins = list(c(-37.8179746, 144.9668636)),
destinations = list(c(-37.81659, 144.9841)),
departure_time = as.POSIXct("2015-01-01"),
key = "abc",
simplify = TRUE),
"departure_time must not be in the past")

})
# test_that("Departure time is not in the past",{
#
# expect_error(google_distance(origins = list(c(-37.8179746, 144.9668636)),
# destinations = list(c(-37.81659, 144.9841)),
# departure_time = as.POSIXct("2015-01-01"),
# key = "abc",
# simplify = TRUE),
# "departure_time must not be in the past")
#
# })

# test_that("waypoints only valid for certain modes",{
#
Expand Down

0 comments on commit d5490c5

Please sign in to comment.