Skip to content

dplyr update causes error in CalculateTrend function #194

@madelinemberger

Description

@madelinemberger

An error message when calculating scores for the OHI+ 4site project revealed an error in CalculateTrends function in OHI core. This error only occurs for people that updated dplyr to version 1.0.0 (me and Gage) whereas people with older version 0.8.5 (Jamie and Sara) did not find this error.

The error message that comes up is:

Calculating Status and Trend for each region for TR...
Error: Problem with `summarise()` input `score`. x subscript out of bounds ℹ Input `score` is `ifelse(...)`. ℹ The error occured in row 1.

The error only occurred for goals that had blank dfs for the "status_data" input - AO and TR (This toolbox is mostly dummy data as I am updating it with the OHI+ layers). Within the CalculateTrends function the error occurs on the third line in the if_else() statement nested in summarize()

  r.trend = status_data %>%
    dplyr::group_by(region_id) %>%
    dplyr::do(mdl = lm(status ~ year, data=.),
              adjust_trend = .$status[.$year == adj_trend_year]) %>%
    dplyr::summarize(region_id, score = ifelse(coef(mdl)['year']==0, 0, coef(mdl)['year']/adjust_trend * 5)) %>%
    dplyr::ungroup() %>%
    dplyr::mutate(score = ifelse(score>1, 1, score)) %>%
    dplyr::mutate(score = ifelse(score<(-1), (-1), score)) %>%
    dplyr::mutate(score = round(score, 4)) %>%
    dplyr::mutate(dimension = "trend") %>%
    dplyr::select(region_id, score, dimension)

For now I am just going take AO and TR out of my goals CSV since I probably won't need AO and can update TR with real data, but flagging here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions