OHI-Science/ohi-science.github.io

Fixing `Error: Unknown columns 'goal', 'region_id', 'score'`

Opened this issue · 0 comments

Recently, the OHI+ Arctic (ARC) updated the goal function for NP. When running this function from within functions.r, it was fine. But when running CalculateAll(), it failed.

I investigated it and fixed it, here's my whole troubleshooting process:

From calculate_scores.r:

## run the configure_toolbox.r script to check configuration
source('~/github/arc/circle2016/configure_toolbox.r')

## calculate scenario scores
scores = ohicore::CalculateAll(conf, layers)

Running Setup()...
Calculating Status and Trend for each region for FIS...
Calculating Status and Trend for each region for MAR...
Calculating Status and Trend for each region for AO...
Calculating Status and Trend for each region for NP...
Error: Unknown columns 'goal', 'region_id', 'score'

This error happened in the NP goal function, and from the looks of it it has something to do with the scores variable, which I know should have column headers 'goal', 'region_id', 'dimension', and 'score'.

So I went into functions.r and started running the NP code line by line (which is possible since I already ran configure_toolbox.r):

...and everything worked. So I looked at the scores variable; it has only 3 columns

head(scores)
Source: local data frame [6 x 3]
Groups: rgn_id [3]

  rgn_id dimension score2
   <int>     <chr>  <dbl>
1      1    status  87.50
2      1     trend   0.50
3      2    status  88.00
4      2     trend   0.21
5      4    status  70.50
6      4     trend   0.08

So I've reformatted scores: here are the commits: 839cd4ed and 6f960eb to see exactly how I fixed them line-by-line.

Now, it calculates everything except fails on the Pressures--the next step for ARC will be to make sure the Pressures Matrix represents ARC as it is now before that will work.

But the NP function in functions.r works! Nice job!!