Skip to contents

Streamlined version of using `left_join`, `rename`, and `relocate` to add human-readable text to a dataframe with stock_id or similar columns. Automatically detects species and `stock_id` column; user can specify species or alternative name for stock_d column if needed.

Usage

label_stocks(.data, species = NULL, stocks_col = "stock_id")

Arguments

.data

Dataframe containing `stock_id` column (or analogous column with different name specied by `stocks_col` argument)

species

character atomic identifying either "CHINOOK" or "COHO" (or variations of those). Defaults to `NULL`; only needed if `.data` does not have species defined as an attribute. Tables read from a fram database using `framrsquared` package automatically have appropriate species attribute.

stocks_col

character atomic identifying the column treated as containing stock_id values Defaults to `stock_id`.

Value

Data frame with additional column `stock_label`

Examples

## create example data
dat = data.frame(stock_id = sample(1:73, size = 10, replace = TRUE))
## Add stock information
dat |> label_stocks(species = "CHINOOK")
#>    stock_id                          stock_label
#> 1        43 UnMarked CR Bonneville Pool Hatchery
#> 2         5       UnMarked Nooksack Spr Hatchery
#> 3        44   Marked CR Bonneville Pool Hatchery
#> 4        61          UnMarked Fraser River Early
#> 5        34          Marked Hood Canal Fall Year
#> 6        70           Marked Central Valley Fall
#> 7        63        UnMarked Lower Georgia Strait
#> 8         4         Marked Nooksack Spr Hatchery
#> 9        34          Marked Hood Canal Fall Year
#> 10       35             UnMarked JDF Tribs. Fall