Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dplyr update causes error in CalculateTrend function #194

Open
madelinemberger opened this issue Jun 26, 2020 · 0 comments
Open

dplyr update causes error in CalculateTrend function #194

madelinemberger opened this issue Jun 26, 2020 · 0 comments

Comments

@madelinemberger
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant