Produces an object suitable to pass as the funcresp to spec_rescomp().

funcresp_custom(func, spnum = NULL, resnum = NULL)

Arguments

func

A function that takes resources (a numeric vector of resource concentrations) and params (a list of parameters) and returns a matrix of growth rates of each species on each resource.

spnum

The number of species; the number of rows in the matrix returned by func.

resnum

The number of resources; the expected length of the resources argument to func and the number of columns in the matrix returned by func.

Value

S3 object of class rescomp_funcresp.

Details

If spnum or resnum are NULL, spec_rescomp() will attempt to infer them. This is fine if the result is passed directly to spec_rescomp(), but may fail if the result must be combined with other rescomp_funcresps first.

Examples

# Type 1 functional response with fixed growth rates
funcresp_custom(
  function(resources, params) {
    growth_rates <- c(0.2, 0.3)
    outer(growth_rates, resources)
  },
  spnum = 2
)
#> $func
#> function (resources, params) 
#> {
#>     growth_rates <- c(0.2, 0.3)
#>     outer(growth_rates, resources)
#> }
#> <environment: 0x136b2bf38>
#> 
#> $spnum
#> [1] 2
#> 
#> $resnum
#> NULL
#> 
#> attr(,"class")
#> [1] "rescomp_funcresp_custom" "rescomp_funcresp"