Skip to content

Commit 8266615

Browse files
authored
Merge pull request #12 from biocro/na-leaf
Allow partitioned leaf mass to be `NA`
2 parents 7823875 + d458660 commit 8266615

6 files changed

Lines changed: 17 additions & 5 deletions

File tree

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2626
- {os: ubuntu-latest, r: 'release'}
2727
- {os: ubuntu-latest, r: 'oldrel-1'}
28-
- {os: ubuntu-latest, r: '4.0.0'}
28+
- {os: ubuntu-latest, r: '4.1.0'}
2929

3030
env:
3131
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: BioCroField
2-
Version: 0.3.0-0
2+
Version: 0.3.0-1
33
Title: Tools for BioCro Field Data
44
Description: A collection of tools for processing field data related to BioCro
55
crop growth simulations.
@@ -12,7 +12,7 @@ Authors@R: c(
1212
License: MIT + file LICENSE
1313
Encoding: UTF-8
1414
LazyData: true
15-
Depends: R (>= 4.0.0)
15+
Depends: R (>= 4.1.0)
1616
Imports:
1717
rmarkdown,
1818
BioCro

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ for the next release.
2222
`biomass_table`.
2323
- Values of `time` are now calculated using `BioCro::add_time_to_weather_data`
2424
to ensure they are always consistent with BioCro's time definition.
25+
- Values of partitioned leaf mass can be set to `NA` when creating a
26+
`harvest_point`, which is treated as if the leaf mass had not been provided.
2527

2628
# BioCroField VERSION 0.3.0
2729

R/harvest_point.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ harvest_point <- function(
190190
# Do not allow a leaf with zero area but nonzero mass
191191
if (!is.na(partitioning_leaf_area) && partitioning_leaf_area == 0 &&
192192
!is.null(partitioning_component_weights[['leaf']]) &&
193+
!is.na(partitioning_component_weights[['leaf']]) &&
193194
partitioning_component_weights[['leaf']] > 0) {
194195
stop("It is not possible for a leaf with zero area to have a nonzero mass")
195196
}
196197

197198
# Do not allow a leaf with zero mass but nonzero area
198199
if (!is.na(partitioning_leaf_area) && partitioning_leaf_area > 0 &&
199200
!is.null(partitioning_component_weights[['leaf']]) &&
201+
!is.na(partitioning_component_weights[['leaf']]) &&
200202
partitioning_component_weights[['leaf']] == 0) {
201203
stop("It is not possible for a leaf with zero mass to have a nonzero area")
202204
}

tests/testthat/test-harvest_point.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ test_that("Missing density parameters are automatically calculated", {
156156
harvest_point(row_spacing = 0.75, plant_spacing = 0.2)$planting_density,
157157
26980
158158
)
159-
159+
160160
expect_equal(
161161
harvest_point(row_spacing = 0.75, planting_density = 26980)$plant_spacing,
162162
0.2
163163
)
164-
164+
165165
expect_equal(
166166
harvest_point(plant_spacing = 0.2, planting_density = 26980)$row_spacing,
167167
0.75
@@ -218,3 +218,9 @@ test_that("Additional arguments must have length 1 and be numeric, character, or
218218
"The following inputs should have length 1, but do not: construct"
219219
)
220220
})
221+
222+
test_that("Partitioned leaf mass can be NA when leaf area is numeric", {
223+
expect_no_error(
224+
harvest_point(partitioning_component_weights = list(leaf = NA), partitioning_leaf_area = 1)
225+
)
226+
})

tests/testthat/test-process.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ test_that("LMA is calculated only when possible", {
122122
expect_na(hpp$LMA)
123123

124124
expect_na(process(harvest_point(partitioning_leaf_area = 1))$LMA)
125+
126+
expect_na(process(harvest_point(partitioning_component_weights = list(leaf = NA), partitioning_leaf_area = 1))$LMA)
125127

126128
expect_na(process(harvest_point(partitioning_component_weights = list(leaf = 1)))$LMA)
127129

0 commit comments

Comments
 (0)