Skip to content

Commit

Permalink
Closes #348
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Sep 8, 2023
1 parent d99c719 commit d07e676
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions r-package/R/accessibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ accessibility <- function(r5r_core,
opportunities <- assign_opportunities(destinations, opportunities_colnames)
mode_list <- assign_mode(mode, mode_egress)
departure <- assign_departure(departure_datetime)

# cap trip duration with cutoffs
if(!is.null(cutoffs)){
max_trip_duration <- ifelse(max_trip_duration > max(cutoffs), max(cutoffs), max_trip_duration)

if(max_trip_duration < max(cutoffs)){stop("'max_trip_duration' cannot be shorter than 'max(cutoffs)'")}
}

max_walk_time <- assign_max_street_time(
max_walk_time,
walk_speed,
Expand All @@ -201,6 +209,10 @@ accessibility <- function(r5r_core,
max_walk_time,
max_bike_time
)




decay_list <- assign_decay_function(decay_function, decay_value)

set_time_window(r5r_core, time_window)
Expand Down
6 changes: 6 additions & 0 deletions r-package/tests/testthat/test-accessibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ test_that("adequately raises errors", {
expect_error(tester(r5r_core, departure_datetime = "13-05-2019 14:00:00"))
expect_error(tester(r5r_core, numeric_datetime))


# errors related to max_trip_duration
expect_error(tester(r5r_core, cutoffs = 10, max_trip_duration = 5))
expect_error(tester(r5r_core, max_trip_duration = "1000"))
expect_error(tester(r5r_core, max_trip_duration = NULL))

# errors related to max_walk_time
expect_error(tester(r5r_core, max_walk_time = "1000"))
expect_error(tester(r5r_core, max_walk_time = NULL))
Expand Down
2 changes: 1 addition & 1 deletion r-package/vignettes/fare_structure.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ calculate_accessibility <- function(fare, fare_string) {
format = "%d-%m-%Y %H:%M:%S"),
opportunities_colname = "healthcare",
mode = c("WALK", "TRANSIT"),
cutoffs = c(60),
cutoffs = 45,
fare_structure = fare_structure,
max_fare = fare,
max_trip_duration = 45,
Expand Down

0 comments on commit d07e676

Please sign in to comment.