## ----setup, message=FALSE, warning=FALSE--------------------------------------
library(dplyr)
library(tidyr)
library(pfwim)

# Load example data included in the package
data("traits", package = "pfwim")
data("feeding_rules", package = "pfwim")

## ----trait-preview------------------------------------------------------------
# Preview the input structure
head(traits)

## ----rules-preview------------------------------------------------------------
# Preview the input structure
head(feeding_rules)

## ----infer-edgelist-----------------------------------------------------------

edgelist <- infer_edgelist(
  data = traits,
  cat_combo_list = feeding_rules,
  col_taxon = "species",
  certainty_req = "all",
  hide_printout = TRUE
)

head(edgelist)

## ----powerlaw-webs------------------------------------------------------------
realised_webs <- powerlaw_prey(
  el = edgelist,
  n_samp = 5,
  y = 2.5
)

# Inspect first realised web
realised_webs[[1]]

## ----custom-func--------------------------------------------------------------
# Define a custom in-degree distribution function
custom_func <- function(r, M, y) (M - r + 1)^(-y)

realised_webs_custom <- powerlaw_prey(
  el = edgelist,
  n_samp = 5,
  y = 2,
  func = custom_func
)

# First custom web
realised_webs_custom[[1]]

