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

adjust lookup table to calculate cor.A_OS_GV #19

Merged
merged 4 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed
* Fixed typo if mais in `ind_managment`
* Fixed test for winderodibility
* Use the correct correction factor in `calc_sealing_risk` #19

## Version 0.8.0 2019-08-02
### Added
Expand Down
4 changes: 2 additions & 2 deletions R/sealing.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ calc_sealing_risk <- function(A_CLAY_MI, A_OS_GV) {
dt[is.na(value), value.A_CLAY_MI := fun.A_CLAY_MI(A_CLAY_MI)]

# Create organic matter correction function and calculate correction for A_OS_GV
fun.cor.A_OS_GV <- approxfun(x = df.lookup$value.A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2)
dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(value.A_CLAY_MI)]
fun.cor.A_OS_GV <- approxfun(x = df.lookup$A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2)
dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(A_CLAY_MI)]

# Calculate the value
dt[is.na(value), value := value.A_CLAY_MI + cor.A_OS_GV * A_OS_GV]
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-sealing.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ test_that("calc_sealing works", {
A_CLAY_MI = 20,
A_OS_GV = 5
),
expected = 8.625,
expected = 8.4375,
tolerance = 0.001
)
expect_equal(
calc_sealing_risk(
A_CLAY_MI = c(25, 20),
A_OS_GV = c(1.5, 8)
),
expected = c(8.6, 10.5),
expected = c(8.6, 10.2),
tolerance = 0.001
)
})
Expand Down