Skip to content

Commit

Permalink
style: styler & lintr pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rCarto committed May 6, 2024
1 parent e9d8a8b commit 6a4a46e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions R/osrmTrip.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified",
test_http_error(r)
res <- RcppSimdJson::fparse(rawToChar(r$content))

# return(res)

# Get all the waypoints
waypointsg <- data.frame(res$waypoints[, c(1, 2, 5)],
matrix(unlist(res$waypoints$location),
byrow = T, ncol = 2
byrow = TRUE, ncol = 2
),
id = loc$id
)
Expand All @@ -118,7 +118,7 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified",
for (nt in 1:ntour) {
# Coordinates of the line
geodf <- data.frame(res$trips[nt, ]$geometry[[1]]$coordinates)
geodf$id <- 1:nrow(geodf)
geodf$id <- seq_len(nrow(geodf))

# In case of unfinnish trip
if (geodf[nrow(geodf), 1] != geodf[1, 1]) {
Expand All @@ -128,7 +128,7 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified",
# Extract trip waypoints
waypoints <- waypointsg[waypointsg$trips_index == (nt - 1), ]
geodf$id_wp <- NA
waypoints <- waypoints[order(waypoints$waypoint_index, decreasing = F), ]
waypoints <- waypoints[order(waypoints$waypoint_index, decreasing = FALSE), ]
j <- 1
for (i in 1:(nrow(geodf) - 1)) {
if (any(geodf[i, c("X1", "X2")] == waypoints[j, c("X1", "X2")])) {
Expand All @@ -146,15 +146,15 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified",

l <- list()
j <- 1
for (i in 1:nrow(geodf)) {
for (i in seq_len(nrow(geodf))) {
if (!is.na(geodf[i, "id_wp"])) {
l[[j]] <- geodf[i, "id"]
j <- j + 1
}
}
# Build the polylines
wktl <- rep(NA, nrow(waypoints))
for (i in 1:length(wktl)) {
for (i in seq_along(wktl)) {
aind <- l[[i]]:l[[i + 1]]
wktl[i] <- paste("LINESTRING(",
paste(geodf[aind, 1], " ",
Expand All @@ -165,7 +165,7 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified",
sep = ""
)
}
start <- (waypoints[order(waypoints$waypoint_index, decreasing = F), "id"])
start <- (waypoints[order(waypoints$waypoint_index, decreasing = FALSE), "id"])
end <- start[c(2:length(start), 1)]
sldf <- st_sf(
start = start, end = end,
Expand Down
14 changes: 7 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ tab_format <- function(res, src, dst, type) {
coord_format <- function(res, src, dst) {
sources <- data.frame(matrix(
unlist(res$sources$location,
use.names = T
use.names = TRUE
),
ncol = 2, byrow = T,
ncol = 2, byrow = TRUE,
dimnames = list(src$id, c("lon", "lat"))
))
destinations <- data.frame(matrix(
unlist(res$destinations$location,
use.names = T
use.names = TRUE
),
ncol = 2, byrow = T,
ncol = 2, byrow = TRUE,
dimnames = list(dst$id, c("lon", "lat"))
))
return(list(sources = sources, destinations = destinations))
Expand Down Expand Up @@ -135,8 +135,8 @@ input_route <- function(x, id, single = TRUE, all.ids = FALSE) {
oprj <- NA
if (single) {
if (is.vector(x)) {
if (length(x) == 2 & is.numeric(x)) {
if (x[1] > 180 | x[1] < -180 | x[2] > 90 | x[2] < -90) {
if (length(x) == 2 && is.numeric(x)) {
if (x[1] > 180 || x[1] < -180 || x[2] > 90 || x[2] < -90) {
stop(
paste0(
"longitude is bounded by the interval [-180, 180], ",
Expand Down Expand Up @@ -191,7 +191,7 @@ input_route <- function(x, id, single = TRUE, all.ids = FALSE) {
idx <- id
}
x <- unlist(x)
if (length(x) == 2 & is.numeric(x)) {
if (length(x) == 2 && is.numeric(x)) {
lon <- clean_coord(x[1])
lat <- clean_coord(x[2])
return(list(id = idx, lon = lon, lat = lat, oprj = oprj))
Expand Down

0 comments on commit 6a4a46e

Please sign in to comment.