munterfinger / hereR
Showing 5 of 14 files from the diff.

@@ -7,7 +7,7 @@
Loading
7 7
#' to obtain an estimate of the consumption.
8 8
#'
9 9
#' @references
10 -
#' \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/index.html}{HERE Routing API: Calculate Route}
10 +
#' \href{https://developer.here.com/documentation/routing-api/dev_guide/index.html}{HERE Routing API: Calculate Route}
11 11
#'
12 12
#' @param origin \code{sf} object, the origin locations of geometry type \code{POINT}.
13 13
#' @param destination \code{sf} object, the destination locations of geometry type \code{POINT}.
@@ -19,7 +19,7 @@
Loading
19 19
#' @param traffic boolean, use real-time traffic or prediction in routing (\code{default = TRUE})? If no traffic is selected, the \code{datetime} is set to \code{"any"} and the request is processed independently from time.
20 20
#' @param avoid_area, \code{sf} object, area (only bounding box is taken) to avoid in routes (\code{default = NULL}).
21 21
#' @param avoid_feature character, transport network features to avoid, e.g. \code{"tollRoad"} or \code{"ferry"} (\code{default = NULL}).
22 -
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
22 +
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
23 23
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
24 24
#'
25 25
#' @return

@@ -16,6 +16,7 @@
Loading
16 16
#' @param arrival boolean, calculate connections for arrival at the defined time (\code{default = FALSE})?
17 17
#' @param results numeric, maximum number of suggested public transport routes (Valid range: 1 and 6).
18 18
#' @param transfers numeric, maximum number of transfers allowed per route (Valid range: -1 and 6, whereby the \code{default = -1} allows for unlimited transfers).
19 +
#' @param transport_mode character, enable or disable (\code{"-"} prefix) transport modes. Note: Do not enable and disable modes at the same time (\code{default = NULL}).
19 20
#' @param summary boolean, return a summary of the public transport connections instead of the sections of the routes (\code{default = FALSE})?
20 21
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
21 22
#'
@@ -40,7 +41,8 @@
Loading
40 41
#' )
41 42
connection <- function(origin, destination, datetime = Sys.time(),
42 43
                       arrival = FALSE, results = 3, transfers = -1,
43 -
                       summary = FALSE, url_only = FALSE) {
44 +
                       transport_mode = NULL, summary = FALSE,
45 +
                       url_only = FALSE) {
44 46
  # Checks
45 47
  .check_points(origin)
46 48
  .check_points(destination)
@@ -49,6 +51,7 @@
Loading
49 51
  .check_numeric_range(transfers, -1, 6)
50 52
  .check_datetime(datetime)
51 53
  .check_boolean(arrival)
54 +
  .check_transport_mode(transport_mode, request = "connection")
52 55
  .check_boolean(summary)
53 56
  .check_boolean(url_only)
54 57
@@ -103,6 +106,15 @@
Loading
103 106
    )
104 107
  }
105 108
109 +
  # Add transport modes
110 +
  if (!is.null(transport_mode)) {
111 +
    url <- paste0(
112 +
      url,
113 +
      "&modes=",
114 +
      paste(transport_mode, collapse = ",")
115 +
    )
116 +
  }
117 +
106 118
  # Add route attributes
107 119
  url <- paste0(
108 120
    url,

@@ -117,6 +117,31 @@
Loading
117 117
    if (!transport_mode %in% modes) {
118 118
      stop(.stop_print_transport_modes(mode = transport_mode, modes = modes, request = request))
119 119
    }
120 +
  } else if (request == "connection") {
121 +
    if (!is.null(transport_mode)) {
122 +
      modes_enable <- c(
123 +
        "highSpeedTrain",
124 +
        "intercityTrain",
125 +
        "interRegionalTrain",
126 +
        "regionalTrain",
127 +
        "cityTrain",
128 +
        "bus",
129 +
        "ferry",
130 +
        "subway",
131 +
        "lightRail",
132 +
        "privateBus",
133 +
        "inclined",
134 +
        "aerial",
135 +
        "busRapid",
136 +
        "monorail",
137 +
        "flight",
138 +
        "walk"
139 +
      )
140 +
      modes_disable <- paste0("-", modes_enable)
141 +
      if (!xor(all(transport_mode %in% modes_enable), all(transport_mode %in% modes_disable))) {
142 +
        stop("Invaid value(s) for 'transport_mode'.")
143 +
      }
144 +
    }
120 145
  }
121 146
}
122 147

@@ -16,7 +16,7 @@
Loading
16 16
#' @param transport_mode character, set the transport mode: \code{"car"}, \code{"pedestrian"} or \code{"truck"}.
17 17
#' @param traffic boolean, use real-time traffic or prediction in routing (\code{default = TRUE})? If no traffic is selected, the \code{datetime} is set to \code{"any"} and the request is processed independently from time.
18 18
#' @param optimize, character, specifies how isoline calculation is optimized: \code{"balanced"}, \code{"quality"} or \code{"performance"} (\code{default = "balanced"}).
19 -
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
19 +
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
20 20
#' @param aggregate boolean, aggregate (with function \code{min}) and intersect the isolines from geometry type \code{POLYGON} to geometry type \code{MULTIPOLYGON} (\code{default = TRUE})?
21 21
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
22 22
#'

@@ -65,16 +65,6 @@
Loading
65 65
  # Setup request headers
66 66
  request_headers <- .create_request_headers()
67 67
68 -
  # Switch coordinates to use max request size of 15x100
69 -
  if (nrow(orig_coords) > nrow(dest_coords)) {
70 -
    switch <- TRUE
71 -
    orig_coords_tmp <- orig_coords
72 -
    orig_coords <- dest_coords
73 -
    dest_coords <- orig_coords_tmp
74 -
  } else {
75 -
    switch <- FALSE
76 -
  }
77 -
78 68
  # Create URLs for batches, store original ids and format coordinates
79 69
  batch_size_orig <- 15
80 70
  batch_size_dest <- 100
@@ -147,13 +137,6 @@
Loading
147 137
    )]
148 138
  }
149 139
150 -
  # Switch back indices
151 -
  if (switch) {
152 -
    tmp <- route_mat$orig_id
153 -
    route_mat$orig_id <- route_mat$dest_id
154 -
    route_mat$dest_id <- tmp
155 -
  }
156 -
157 140
  # Reorder
158 141
  route_mat <- route_mat[order(
159 142
    route_mat$orig_id,
@@ -226,8 +209,8 @@
Loading
226 209
        # Matrix
227 210
        routes <- data.table::data.table(
228 211
          data.table::CJ(
229 -
            dest_id = dest_idx[[count]][1:df$matrix$numDestinations] + 1,
230 -
            orig_id = orig_idx[[count]][1:df$matrix$numOrigins] + 1
212 +
            orig_id = orig_idx[[count]][1:df$matrix$numOrigins] + 1,
213 +
            dest_id = dest_idx[[count]][1:df$matrix$numDestinations] + 1
231 214
          ),
232 215
          request_id = ids[count],
233 216
          departure = NA,
Files Coverage
R 91.99%
Project Totals (16 files) 91.99%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading