R/get_path.R

Defines functions get_path

Documented in get_path

# get_path from shortestpath

get_path <- function(departure, arrival){
  result <- shortestpath(departure, arrival, max_route=1)[[1]] %>% get_pathresult()
  station <- "no_result"
  index <- result %>% names %>% str_which("Path")
  if(!(result$Time %in% c(300,600))){
    Path <- result[[index[1]]]
    for(i in 2:length(index)){
      Path <- rbind(Path, result[[index[i]]])
    }
    station <- Path$Name %>% unique()
  }
  n_row <- length(station)
  station_1 <- station[1:(n_row-1)]
  station_2 <- station[2:n_row]
  result_set <- data.frame(set=paste0(departure, "-", arrival),
                           from=station_1, to=station_2)
  return(result_set %>% na.omit)
}
king4k1/Seoulsubway documentation built on Nov. 17, 2019, 4:08 p.m.