Skip to content

Commit fefff05

Browse files
authored
Merge pull request PecanProject#3808 from infotroph/suggest-traits
move {traits} to Suggests
2 parents 23df7dd + 6a3fb45 commit fefff05

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

docker/depends/pecan_package_dependencies.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
"tidyverse","*","base/db","Suggests",FALSE
666666
"tools","*","base/remote","Suggests",FALSE
667667
"tools","*","modules/allometry","Imports",FALSE
668-
"traits","*","modules/data.land","Imports",FALSE
668+
"traits","*","modules/data.land","Suggests",FALSE
669669
"TruncatedNormal",">= 2.2","modules/assim.batch","Imports",FALSE
670670
"truncnorm","*","modules/data.atmosphere","Imports",FALSE
671671
"units","*","base/db","Imports",FALSE

modules/data.land/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Imports:
5858
terra,
5959
tidyr,
6060
tidyselect,
61-
traits,
6261
XML (>= 3.98-1.4)
6362
Suggests:
6463
dataone,
@@ -72,6 +71,7 @@ Suggests:
7271
raster,
7372
reticulate,
7473
testthat (>= 3.1.0),
74+
traits,
7575
withr,
7676
MASS
7777
Remotes:

modules/data.land/NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
* `landiq_crop_mapping_codes` dataset mapping LandIQ crop classification codes to human-readable crop names.
1212
* `bism_kc_by_crop` dataset containing BISm crop coefficient schedules and stage timing references for use in ET estimation, including columns that map to LandIQ class and subclass.
1313

14+
## Changed
15+
16+
* Package `traits`, used by `match_pft()` and `match_species_id()` only when no database connection is provided, is now suggested rather than required.
17+
18+
1419
# PEcAn.data.land 1.9.0
1520

1621
## Added

modules/data.land/R/match_pft.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ match_pft <- function(bety_species_id, pfts, query = NULL, con = NULL, allow_mis
3333
query <- paste0(query," AND bp.modeltype_id = ",modeltype$id)
3434
}
3535
translation <- PEcAn.DB::db.query(query, con = con)
36-
37-
38-
}else{ # use traits package
39-
36+
37+
38+
} else { # use traits package
39+
if (!requireNamespace("traits", quietly = TRUE)) {
40+
PEcAn.logger::logger.severe(
41+
"Using match_pft without a Bety connection",
42+
"requires the `traits` package, which is not installed."
43+
)
44+
}
45+
4046
bety_list <- list()
41-
47+
4248
for (pft in pfts) {
4349
# query pft id
4450
bety_pft <- traits::betydb_query(name = pft$name, modeltype_id = model$id, table = 'pfts', user = 'bety', pwd = 'bety')

modules/data.land/R/match_species_id.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ match_species_id <- function(input_codes, format_name = 'custom', bety = NULL, t
8787
translation,
8888
data.frame(input_code = input_codes, stringsAsFactors = FALSE),
8989
by = "input_code")
90-
}else{
90+
} else {
9191
# use traits package
92+
if (!requireNamespace("traits", quietly = TRUE)) {
93+
PEcAn.logger::logger.severe(
94+
"Using match_species_id without a Bety connection",
95+
"requires the `traits` package, which is not installed."
96+
)
97+
}
9298

9399
# can call traits::betydb_query one at a time?
94100
# reduce the number of calls

modules/data.land/tests/Rcheck_reference.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* package encoding: UTF-8
1414
* checking package namespace information ... OK
1515
* checking package dependencies ... NOTE
16-
Imports includes 35 non-default packages.
16+
Imports includes 34 non-default packages.
1717
Importing from so many packages makes the package vulnerable to any of
1818
them becoming unavailable. Move as many as possible to Suggests and
1919
use conditionally.

0 commit comments

Comments
 (0)