From d889ee568d8ef9382090cc58f712aaf5391603c3 Mon Sep 17 00:00:00 2001 From: oweno-tfwm Date: Fri, 22 Sep 2023 21:09:18 +0100 Subject: [PATCH] if stop doesn't exist in TIPLOC file - put tiploc code name into route name instead of NA --- R/atoc_export.R | 5 +++-- R/atoc_nr.R | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/R/atoc_export.R b/R/atoc_export.R index 8a70d91..d8391b8 100644 --- a/R/atoc_export.R +++ b/R/atoc_export.R @@ -161,15 +161,16 @@ longnames <- function(routes, stop_times, stops) { stop_times_sub, dplyr::rename(stops[, c("stop_id", "stop_name")], stop_name_a = stop_name), by = c("stop_id_a" = "stop_id")) + stop_times_sub <- dplyr::left_join( stop_times_sub, dplyr::rename(stops[, c("stop_id", "stop_name")], stop_name_b = stop_name), by = c("stop_id_b" = "stop_id")) stop_times_sub$route_long_name <- paste0("from ", - stop_times_sub$stop_name_a, + ifelse( is.na(stop_times_sub$stop_name_a), stop_times_sub$stop_id_a, stop_times_sub$stop_name_a), " to ", - stop_times_sub$stop_name_b) + ifelse( is.na(stop_times_sub$stop_name_b), stop_times_sub$stop_id_b, stop_times_sub$stop_name_b) ) stop_times_sub$route_long_name <- gsub(" Rail Station", "" , stop_times_sub$route_long_name) diff --git a/R/atoc_nr.R b/R/atoc_nr.R index 7cbe8e0..f1ea53a 100644 --- a/R/atoc_nr.R +++ b/R/atoc_nr.R @@ -164,9 +164,9 @@ getCachedLocationData <- function(locations = "tiplocs") if (inherits(locations, "sf")) { stops <- cbind(locations, sf::st_coordinates(locations)) - stops <- as.data.frame(stops) - stops <- stops[, c( "stop_id", "stop_code", "stop_name", "Y", "X" )] - names(stops) <- c( "stop_id", "stop_code", "stop_name", "stop_lat", "stop_lon" ) + stops <- sf::st_drop_geometry(stops) + stops <- as.data.table(stops) + setnames(stops, old = c("Y", "X"), new = c("stop_lat", "stop_lon")) } else #TODO test column names {