Add standard_result S3 class for unified preprocessing return values.#4015
Add standard_result S3 class for unified preprocessing return values.#4015shreyannandanwar wants to merge 1 commit into
Conversation
| #' `status == "error"`. | ||
| #' | ||
| #' @return An object of class `pecan_preprocess_result`. | ||
| #' @export |
There was a problem hiding this comment.
I'd suggest adding the @md tag somewhere in this Roxygen doc. Otherwise, the syntax highlighting may not be visible/render correctly.
There was a problem hiding this comment.
should be done for other functions as well.
| allowed_status <- c("success", "error", "skipped") | ||
|
|
||
| if (!inherits(x, "pecan_preprocess_result")) { | ||
| stop("`x` must inherit from 'pecan_preprocess_result'.", call. = FALSE) |
There was a problem hiding this comment.
I'd suggest using PEcAn.logger::logger.severe() instead of these stop() for consistency with rest of the codebase
| "base/workflow/R/standard_result.R", | ||
| "R/standard_result.R", | ||
| "../../R/standard_result.R", | ||
| "/Users/hm/Desktop/pecan/base/workflow/R/standard_result.R" |
There was a problem hiding this comment.
Nit: this absolute /Users/... path seems environment-specific. Not sure if this should be included or not.
There was a problem hiding this comment.
thanks, for the feedback
I will work on it.
There was a problem hiding this comment.
More generally, none of these paths should be hard coded. First, its unclear why a test would need to source any R file that's part of the package as the functions should be loaded already. Second, if you do need to load a file from within a package use system.file instead
mdietze
left a comment
There was a problem hiding this comment.
High-level comment that "standard_result" is an incredibly generic and non-descriptive name for any application. Its also a particularly bad choice for a class that processes inputs rather than outputs, as "result" and "output" are pretty much synonyms.
| #' @return `x`, invisibly, when validation succeeds. | ||
| #' @export | ||
| validate_standard_result <- function(x) { | ||
| allowed_tags <- c("met", "soil", "ic", "phenology", "fia") |
There was a problem hiding this comment.
I don't like the idea of hard coding the allowable tags within a low-level function. If the goal is to replace the BETY input type table, note that this table had been designed specifically to allow it to be extensible without recompiling any code. Burying it here means there's yet one more thing people need to remember to do when adding new models or expanding existing models. This specific list is also really incomplete and misleading (e.g., ED2 alone has 9 input tags: met, lu, thsum, veg, soil, pss, site, css, initcond; on the other side AFAIK no model has "fia" as in input tag)
| "base/workflow/R/standard_result.R", | ||
| "R/standard_result.R", | ||
| "../../R/standard_result.R", | ||
| "/Users/hm/Desktop/pecan/base/workflow/R/standard_result.R" |
There was a problem hiding this comment.
More generally, none of these paths should be hard coded. First, its unclear why a test would need to source any R file that's part of the package as the functions should be loaded already. Second, if you do need to load a file from within a package use system.file instead
Summary
Introduces
standard_result()as a standardized S3 return object for preprocessing workflows.This is an additive change and does not modify existing preprocessing behavior. The goal is to establish a common result contract that can be adopted incrementally by functions such as
do_conversions(),met.process(), and related preprocessing utilities.Changes
standard_result()constructoras.data.frame()methodBackward Compatibility
No existing workflow behavior has been modified.
No existing preprocessing functions have been migrated.
This PR only introduces the new abstraction and tests.
Testing
Result:
Full workflow test suite currently contains unrelated failures in
run.write.configs_multisite, reproduced independently of this change.Future Work
met.process()convert_input()do_conversions()Review Time Estimate
Types of changes
Checklist: