Skip to contents

The data frame needs to have the columns "species", "w_pred", "w_prey" and "n_prey". The function adds a log_ppmr column to the data frame with the logarithm of the predator/prey mass ratio.

Usage

validate_ppmr_data(ppmr_data, species = NULL)

Arguments

ppmr_data

A data frame with log ppmr observations

species

The species to select. Optional. If supplied the function only selects the rows for the specified species. If the species is not found, an error is raised.

Value

Valid ppmr data frame with columns "species", "w_pred", "w_prey", "n_prey" and "log_ppmr" and rows for the specified species.

Details

If a log_ppmr column already exists, it is overwritten and a warning is issued if discrepancies were found. A warning is also issued if any prey is heavier than the predator.

See also

Examples

# Validate the barnes_data dataset
valid_data <- validate_ppmr_data(barnes_data)
head(valid_data)
#> # A tibble: 6 × 5
#>   species               w_pred w_prey n_prey log_ppmr
#>   <chr>                  <dbl>  <dbl>  <dbl>    <dbl>
#> 1 Atlantic bluefin tuna  61666   3.51      1     9.77
#> 2 Atlantic bluefin tuna  61666   3.51      1     9.77
#> 3 Atlantic bluefin tuna  61666   3.51      1     9.77
#> 4 Atlantic bluefin tuna  61666   4.63      1     9.50
#> 5 Atlantic bluefin tuna  61666   4.63      1     9.50
#> 6 Atlantic bluefin tuna  61666   4.63      1     9.50

# Validate and filter to a single species
cod_data <- validate_ppmr_data(barnes_data, species = "Atlantic cod")
nrow(cod_data)
#> [1] 2518