From 6a4a46e1a9618c04cf9d276008cd91635bd5388e Mon Sep 17 00:00:00 2001 From: rCarto Date: Mon, 6 May 2024 15:19:10 +0200 Subject: [PATCH] style: styler & lintr pass --- R/osrmTrip.R | 14 +++++++------- R/utils.R | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/R/osrmTrip.R b/R/osrmTrip.R index 732f072..c7e56f9 100644 --- a/R/osrmTrip.R +++ b/R/osrmTrip.R @@ -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 ) @@ -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]) { @@ -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")])) { @@ -146,7 +146,7 @@ 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 @@ -154,7 +154,7 @@ osrmTrip <- function(loc, exclude = NULL, overview = "simplified", } # 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], " ", @@ -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, diff --git a/R/utils.R b/R/utils.R index 9e90d14..16e50f3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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)) @@ -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], ", @@ -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))