From d5490c5e6e0f28d0e885744fdbd493c09ca7ed9f Mon Sep 17 00:00:00 2001 From: SymbolixAU Date: Thu, 2 Aug 2018 07:58:58 +1000 Subject: [PATCH] departure and arrival times since 1970 - for #170 --- R/google_directions.R | 9 +++--- R/google_distance.R | 30 +------------------- R/parameter_checks.R | 6 ++-- man/google_directions.Rd | 9 +++--- man/google_distance.Rd | 37 ++++++++++--------------- tests/testthat/test-google_directions.R | 22 +++++++-------- tests/testthat/test-google_distances.R | 20 ++++++------- 7 files changed, 50 insertions(+), 83 deletions(-) diff --git a/R/google_directions.R b/R/google_directions.R index f907ae42..01d5dbe3 100644 --- a/R/google_directions.R +++ b/R/google_directions.R @@ -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 diff --git a/R/google_distance.R b/R/google_distance.R index 47a7c829..2bd5bf98 100644 --- a/R/google_distance.R +++ b/R/google_distance.R @@ -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 diff --git a/R/parameter_checks.R b/R/parameter_checks.R index a6331b70..4066493e 100644 --- a/R/parameter_checks.R +++ b/R/parameter_checks.R @@ -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) } diff --git a/man/google_directions.Rd b/man/google_directions.Rd index d8c14b13..26da845d 100644 --- a/man/google_directions.Rd +++ b/man/google_directions.Rd @@ -21,13 +21,14 @@ coordinates, an address string or a place_id, or a vector of a pair of lat / lon 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} -\item{mode}{string. One of 'driving', 'walking', 'bicycling' or 'transit'.} +\item{mode}{\code{string} One of 'driving', 'walking', 'bicycling' or 'transit'.} -\item{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 +\item{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()}} -\item{arrival_time}{\code{POSIXct}. Specifies the desired time of arrival. Note you +\item{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.} diff --git a/man/google_distance.Rd b/man/google_distance.Rd index b2f08df1..5bc0b1fb 100644 --- a/man/google_distance.Rd +++ b/man/google_distance.Rd @@ -11,22 +11,15 @@ google_distance(origins, destinations, mode = c("driving", "walking", key = get_api_key("distance"), simplify = TRUE, curl_proxy = NULL) } \arguments{ -\item{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} - -\item{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} - \item{mode}{\code{string} One of 'driving', 'walking', 'bicycling' or 'transit'.} -\item{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()}} +\item{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()}} -\item{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. +\item{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.} \item{avoid}{\code{character} vector stating which features should be avoided. @@ -35,25 +28,25 @@ One of 'tolls', 'highways', 'ferries' or 'indoor'} \item{units}{\code{string} metric or imperial. Note: Only affects the text displayed within the distance field. The values are always in metric} -\item{traffic_model}{\code{string}. One of 'best_guess', 'pessimistic' or 'optimistic'. +\item{traffic_model}{\code{string} - one of 'best_guess', 'pessimistic' or 'optimistic'. Only valid with a departure time} \item{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")}} +Only vaid where \code{mode = 'transit'}. Note that 'rail' is equivalent +to \code{transit_mode=c("train", "tram", "subway")}} \item{transit_routing_preference}{\code{vector} strings - one of 'less_walking' and 'fewer_transfers'. specifies preferences for transit routes. Only valid for transit directions.} -\item{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} +\item{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#languagesupport}. +If no langauge is supplied, the service will attempt to use the language of the domain from which the request was sent} -\item{key}{\code{string}. A valid Google Developers Distance API key} +\item{key}{\code{string} - a valid Google Developers Directions API key} -\item{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} +\item{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} \item{curl_proxy}{a curl proxy object} } diff --git a/tests/testthat/test-google_directions.R b/tests/testthat/test-google_directions.R index 088c428f..98930715 100644 --- a/tests/testthat/test-google_directions.R +++ b/tests/testthat/test-google_directions.R @@ -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",{ diff --git a/tests/testthat/test-google_distances.R b/tests/testthat/test-google_distances.R index f0ee58b2..05b3575e 100644 --- a/tests/testthat/test-google_distances.R +++ b/tests/testthat/test-google_distances.R @@ -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",{ #