Skip to content

Conversation

@schwarzmeyer
Copy link
Collaborator

Workflow to implement the exposure analyses using arrays

@carlosgjs carlosgjs self-requested a review June 13, 2025 21:45
@carlosgjs carlosgjs self-assigned this Jun 13, 2025
#' @export
#'

exposure_fast <- function(species.names, species.data, climate.data, niche.data, monthly = TRUE){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of a boolean monthly, it could be useful to have a mode argument that can be set to "monthly" or "extreme", which allows for additional calculations to be added without changing the interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually R/exposure_fast.R should be replaced by array_workflow/exposure.R. I’ve added the mode argument in the latter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Then this file will get removed?

@@ -0,0 +1,122 @@
#' Transform climate data in array format to tibble format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a duplicate of R/array_to_tibble.R? can it be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, R/array_to_tibble.R can be removed. Please keep the code from the array_workflow/code folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great. In that case please remove it from your branch so it doesn't get merged upon completion of your PR


# here I will convert the array into a tibble

lons <- climate$lon + 0.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could source R/array_to_tibble.R instead right? Using the common functions would shorten and simplify this script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, how's is this different from scripts/array_workflow.R?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts/array_workflow.R is an updated, cleaner version of the array_workflow/code/array_to_tibble_workflow.R. It basically shows how all the functions work together. That pdf document I shared on slack is based on the scripts/array_workflow.R. Is this script useful for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous comment, please remove array_workflow/code/array_to_tibble_workflow.R from your branch so it doesn't get merged upon completion of your PR

Basically the aim is to not have duplicate code merged into the main branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like tier_1 folder needs to be removed, it's already under data-raw

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also array_workflow/ needs to be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosgjs
Copy link
Member

@schwarzmeyer you can test the yearly workflow with test data with:

Rscript scripts/main.R exposure --input_yml data-raw/shp_config.yml --workers 1

Currently this fails with:

ℹ Loading biodiversityhorizons
Error in `load_all()`:
! Failed to load R/species_threshold.R
Caused by error:
! object 'climate' not found
Backtrace:
     ▆
  1. ├─global run_exposure(args)
  2. │ └─global exposure_workflow(...)
  3. │   └─devtools::load_all()
  4. │     └─pkgload::load_all(...)
  5. │       └─pkgload::load_code(path, quiet = quiet)
  6. │         ├─withr (local) withr_with_dir(path, source_many(paths, encoding, env))
  7. │         │ └─base::force(code)
  8. │         └─pkgload:::source_many(paths, encoding, env)
  9. │           ├─rlang::try_fetch(...)
 10. │           │ ├─base::tryCatch(...)
 11. │           │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 12. │           │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 13. │           │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 14. │           │ └─base::withCallingHandlers(...)
 15. │           └─pkgload:::source_one(file, encoding, envir = envir)
 16. │             └─base::eval(expr, envir)
 17. │               └─base::eval(expr, envir)
 18. │                 └─base::array(...)
 19. └─base::.handleSimpleError(...)
 20.   └─rlang (local) h(simpleError(msg, call))
 21.     └─handlers[[1L]](cnd)
 22.       └─pkgload:::handle_source_error(cnd, file)
 23.         └─cli::cli_abort(msg, parent = cnd, call = quote(load_all()))
 24.           └─rlang::abort(...)
 25. ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants