# \donttest{
if (identical(Sys.getenv("OSRM_EXAMPLES"), "true")) {
# Install OSRM (temporary, session PATH)
install_dir <- osrm_install(
version = "latest",
path_action = "session",
quiet = TRUE
)
# copy example OSM PBF into a temporary workspace to avoid polluting pkg data
pbf_path <- system.file("extdata/cur.osm.pbf", package = "osrm.backend")
osrm_dir <- file.path(tempdir(), paste0("osrm-", Sys.getpid()))
dir.create(osrm_dir, recursive = TRUE)
tmp_pbf <- file.path(osrm_dir, "cur.osm.pbf")
file.copy(from = pbf_path, to = tmp_pbf, overwrite = TRUE)
# Find the path to the profile first
car_profile <- osrm_find_profile("car.lua")
# extract OSRM graph files
result <- osrm_extract(
input_osm = tmp_pbf,
profile = car_profile,
overwrite = TRUE,
threads = 1L
)
# path to generated .osrm files (specifically, the .osrm.timestamp file)
result$osrm_job_artifact
# Clean up binaries and workspace
osrm_uninstall(
dest_dir = install_dir,
clear_path = TRUE,
force = TRUE,
quiet = TRUE
)
unlink(osrm_dir, recursive = TRUE)
}
# }
Run the code above in your browser using DataLab