Skip to content

Commit

Permalink
Fix continued
Browse files Browse the repository at this point in the history
  • Loading branch information
hahsan1 committed Apr 7, 2024
1 parent d417707 commit d2ea94f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions R/grid_to_basin_yield.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,22 @@ grid_to_basin_yield <- function(carbon = NULL,
dplyr::rowwise() %>%
dplyr::mutate(yield = sum_na(c(swheat_yield, wwheat_yield)))


# Check that ir and rf summed correctly
if(sum(ir_yield_swheat$swheat_yield, ir_yield_wwheat$wwheat_yield, na.rm = TRUE) == sum(ir_yield_wheat$yield, na.rm = TRUE)) {
rlang::inform("Sum of individual irrigated spring and winter wheat yields correctly sum to total irrigated wheat yield")
} else{rlang::inform("Error: Sum of individual irrigated spring and winter wheat yields do not sum to total irrigated wheat yield")}

if(sum(rf_yield_swheat$swheat_yield, rf_yield_wwheat$wwheat_yield) == sum(rf_yield_wheat$yield)) {
if(sum(rf_yield_swheat$swheat_yield, rf_yield_wwheat$wwheat_yield, na.rm = TRUE) == sum(rf_yield_wheat$yield, na.rm = TRUE)) {
rlang::inform("Sum of individual rainfed spring and winter wheat yields correctly sum to total rainfed wheat yield")
} else{rlang::inform("Error: Sum of individual rainfed spring and winter wheat yields do not sum to total rainfed wheat yield")}


# Generate basin yield
ir_yields_basin <- aggregate_halfdeg_yield2basin(ir_yield_wheat)
rf_yields_basin <- aggregate_halfdeg_yield2basin(rf_yield_wheat)
ir_yields_basin <- aggregate_halfdeg_yield2basin(ir_yield_wheat %>%
dplyr::select(-c(swheat_yield, wwheat_yield)))
rf_yields_basin <- aggregate_halfdeg_yield2basin(rf_yield_wheat %>%
dplyr::select(-c(swheat_yield, wwheat_yield)))

dplyr::bind_rows(rf_yields_basin,
ir_yields_basin) ->
Expand Down

0 comments on commit d2ea94f

Please sign in to comment.