## ----modify_traits------------------------------------------------------------

library(pfwim)
library(dplyr)

# Adding body mass to our traits
traits_numeric <- traits %>%
  mutate(body_mass = case_when(
    species == "polar_bear" ~ 450,
    species == "seal"       ~ 100,
    species == "orca"       ~ 3000,
    species == "cod"        ~ 5,
    species == "plankton"   ~ 0.0001,
    TRUE                    ~ 10 # Default for others
  ))

head(traits_numeric)


## ----size_rule----------------------------------------------------------------

my_size_rule <- function(res_size, con_size) {
  ratio <- con_size / res_size
  ifelse(ratio >= 2 & ratio <= 100, 1, 0)
}


## ----build_list---------------------------------------------------------------

edgelist_size <- infer_edgelist(
  data = traits_numeric,
  cat_combo_list = feeding_rules,
  col_taxon = "species",
  col_num_size = "body_mass",    # Point to the numeric column
  num_size_rule = my_size_rule,   # Apply our custom logic
  certainty_req = "all",
  hide_printout = TRUE
)

head(edgelist_size)

