Skip to content

CalculateSafetyMeasures data mask context error #2

@katie-bea-korpi

Description

@katie-bea-korpi

I am encountering an error when running the CalculateSafetyMeasures module from the VETravelPerformance package in the run script. CaclulateSafetyMeasures.R can be found in the repo linked below

https://github.com/VisionEval/VisionEval-4/blob/release/sources/modules/VETravelPerformance/R/CalculateSafetyMeasures.R#L301-309

calculate Bike and Walk PMT from Houshold table and aggregate all households to get the total Marea PMTs

apply the injury and fatal rates to estimate the crashes by type.

Crashes_HH <- HH_df %>%
  dplyr::mutate(BikeMT = (rlang::.data$BikeTrips) * (rlang::.data$BikeAvgTripDist),
         WalkMT = (rlang::.data$WalkTrips) * (rlang::.data$WalkAvgTripDist)) %>%
  dplyr::group_by((rlang::.data$Marea)) %>%
  dplyr::summarise(BikePMT = sum((rlang::.data$BikeMT)),
          WalkPMT = sum((rlang::.data$WalkMT))) %>%
  dplyr::mutate(walkfatal = Marea_df$WalkFatal[[1]] *(rlang::.data$WalkPMT) / (10^8),

This is the error message:

[Error]: Error in dplyr::mutate(BikeMT = (rlang::.data$BikeTrips) * (rlang::.data$BikeAvgTripDist), :
ℹ In argument: BikeMT = (rlang::.data$BikeTrips) * (rlang::.data$BikeAvgTripDist).
Caused by error:
! Can't subset .data outside of a data mask context.

Potential Solution

When a character vector of the column name is used inside the dplyr::mutate function the error does not occur. A potential solution is shown below.

calcualte Bike and Walk PMT from Houshold table and aggregate all housholds to geth the total Marea PMTs

apply the injury and fatal rates to estiamte the crashes by type.

Crashes_HH <- HH_df %>%
  dplyr::mutate(BikeMT = BikeTrips * BikeAvgTripDist,
         WalkMT = WalkTrips * WalkAvgTripDist) %>%
  dplyr::group_by(Marea) %>%
  dplyr::summarise(BikePMT = sum(BikeMT),
          WalkPMT = sum(WalkMT)) %>%
  dplyr::left_join(Marea_df, "Marea") %>%
  dplyr::mutate(walkfatal = WalkFatal *WalkPMT / (10^8),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions