added needed libraries for mainloop

This commit is contained in:
Ben Varick 2024-11-27 09:45:47 -06:00
parent f594e4cbd6
commit 6b081412a0
Signed by: ben
SSH Key Fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo

View File

@ -26,6 +26,8 @@ library(ggmap)
library(sf) library(sf)
library(osrm) library(osrm)
library(reactable) library(reactable)
library(smoothr)
library(httr)
fig.height <- 6 fig.height <- 6
set.seed(1) set.seed(1)
source("./R/functions.R") source("./R/functions.R")
@ -118,27 +120,27 @@ for(j in indexVec){
) )
response <- GET(query) response <- GET(query)
if( response$status_code == "200" ){ if( response$status_code == "200" ) {
route_run <- st_read(content <- content(response, as = "text"), quiet = TRUE) route_run <- st_read(content <- content(response, as = "text"), quiet = TRUE)
routes[[i]] <- route_run routes[[i]] <- route_run
}else{ } else {
routes[[i]] <- NA routes[[i]] <- NA
} }
} }
bad.cell <- which(is.na(routes)) bad.cell <- which(is.na(routes))
if(length(bad.cell) > 0){ if(length(bad.cell) > 0) {
routes <- routes[-bad.cell] routes <- routes[-bad.cell]
grid <- grid[-bad.cell,] grid <- grid[-bad.cell,]
} }
if(length(routes) > 0){ if(length(routes) > 0) {
routes <- st_transform(bind_rows(routes), crs = 4326) routes <- st_transform(bind_rows(routes), crs = 4326)
gridList[[jj]] <- grid gridList[[jj]] <- grid
routesList[[jj]] <- routes routesList[[jj]] <- routes
jj <- jj + 1 jj <- jj + 1
}else{ } else {
routes <- NA routes <- NA
bad.school.vec <- c(j, bad.school.vec) bad.school.vec <- c(j, bad.school.vec)
cat( WI_schools$SCHOOL[j], "has zero routes to school and has been removed from analysis.\n") cat( WI_schools$SCHOOL[j], "has zero routes to school and has been removed from analysis.\n")
@ -146,7 +148,7 @@ for(j in indexVec){
} }
if(length(bad.school.vec) > 0){ if(length(bad.school.vec) > 0) {
WI_schools <- WI_schools[-bad.school.vec,] WI_schools <- WI_schools[-bad.school.vec,]
} }