forsys-sp / forsysr

An R implementation of the ForSys program
GNU General Public License v3.0
8 stars 3 forks source link

Run function failing #113

Open michelledayusfs opened 10 months ago

michelledayusfs commented 10 months ago

I have been using Forsys for R and it worked great until recently. I updated R and now the 'run' function is not working, I keep getting the message that:

Error in filter(): ℹ In argument: get(global_ceiling_field) <= global_ceiling_value. Caused by error in get(): ! invalid first argument Run rlang::last_trace() to see where the error occurred.

JosephStewart commented 10 months ago

Perhaps "filter" needs to be replaced with "dplyr::filter"? This is a common issue I run into with my (non-forsys) code.

Joseph Stewart Postdoc, UC Davis StewartEcology.org http://stewartecology.org/ ReforestationTools.org

On Thu, Jan 4, 2024 at 2:19 PM Michelle Day @.***> wrote:

I have been using Forsys for R and it worked great until recently. I updated R and now the 'run' function is not working, I keep getting the message that:

Error in filter(): ℹ In argument: get(global_ceiling_field) <= global_ceiling_value. Caused by error in get(): ! invalid first argument Run rlang::last_trace() to see where the error occurred.

— Reply to this email directly, view it on GitHub https://github.com/forsys-sp/forsysr/issues/113, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQFWZVOTX3ZOI52GD4EVVLYM4TFVAVCNFSM6AAAAABBNSZA7CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DMNBRGE3TCMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

codyevers commented 10 months ago

I’ll look into this. I know it’s best practice to declare the package namespace to prevent conflicts (say after importing a new package). More tomorrow… On Jan 4, 2024 at 5:04 PM -0600, JosephStewart @.***>, wrote:

Perhaps "filter" needs to be replaced with "dplyr::filter"? This is a common issue I run into with my (non-forsys) code.

Joseph Stewart Postdoc, UC Davis StewartEcology.org http://stewartecology.org/ ReforestationTools.org

On Thu, Jan 4, 2024 at 2:19 PM Michelle Day @.***> wrote:

I have been using Forsys for R and it worked great until recently. I updated R and now the 'run' function is not working, I keep getting the message that:

Error in filter(): ℹ In argument: get(global_ceiling_field) <= global_ceiling_value. Caused by error in get(): ! invalid first argument Run rlang::last_trace() to see where the error occurred.

— Reply to this email directly, view it on GitHub https://github.com/forsys-sp/forsysr/issues/113, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQFWZVOTX3ZOI52GD4EVVLYM4TFVAVCNFSM6AAAAABBNSZA7CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DMNBRGE3TCMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were assigned.Message ID: @.***>

michelledayusfs commented 10 months ago

I replicated the error with this code:

library(forsys) library(patchmax) library(sf) library(dplyr)

data(test_forest) stand_dat <- test_forest %>% st_drop_geometry()

run_outputs <- forsys::run( return_outputs = TRUE, scenario_name = "test_scenario", stand_data = stand_dat, stand_id_field = "stand_id", proj_id_field = "proj_id", stand_area_field = "area_ha", scenario_priorities = "priority1", scenario_output_fields = c("area_ha", "priority1", "priority2", "priority3", "priority4"), proj_fixed_target = TRUE, proj_target_field = "area_ha", proj_target_value = 2000 )

michelledayusfs commented 10 months ago

I also tried running this with patchmax looking to see if the problem is isolated to running forsys with predefined planning areas. I got a different error-- not sure if this is helpful or a separate issue:

stand_dat <- test_forest

run_outputs <- forsys::run( return_outputs = TRUE, scenario_name = "test_scenario", stand_data = stand_dat, stand_id_field = "stand_id", stand_area_field = "area_ha", scenario_priorities = "priority1", scenario_output_fields = c("area_ha", "priority1", "priority2", "priority3", "priority4"), run_with_patchmax = TRUE, patchmax_proj_number = 3, patchmax_proj_size = 2000 )

Writing data to C:/GitHub/forsysr/output/test_scenario Weighting scenario 1 of 1: 1 Combined priority assigned to weightedPriority Starting year 1 ---------------- Error in loadNamespace(x) : there is no package called ‘checkmate’

codyevers commented 10 months ago

There were two different issues. Both should be addressed with the latest commit.

Issue #1 re global_ceiling_field resulted when the global_ceiling_value was unspecified and dynamic patches were generated. This is addressed in forsysr repo.

Issue #2 re checkmate required updating NAMESPACE to include checkmate package that I substituted for the previous assertive package after realizing the later is no longer available on CRAN.

Please check that both issues are resolved. If so, we can close this issue.

codyevers commented 10 months ago

Just for documentation, in #1, I changed the default global_ceiling_value from NULL to Inf.

Also, for #2 I added checkmate to the DESCRIPTION file where dependencies are declared.

melBoyd commented 10 months ago

It works for me now. Thank you!!