Learn R Programming

ForestElementsR (version 2.0.1)

fe_species_master: Construct a fe_species_master Species Code Vector

Description

User interface for constructing a vector of species codes follwing the fe_species_master convention

Usage

fe_species_master(x = character())

Value

If the user input allows to construct a well-defined fe_species_master object, this object will be returned. If not, the function will terminate with an error.

Arguments

x

Input vector to become a vector of tree species codes by the definition master. Any type of vector (typically integer) which, after conversion with as.character, adheres to that definition is acceptable. If x is provided as a character vector, leading and trailing white spaces will be trimmed.

Details

The master species coding is the original species coding used by the package ForestElementsR. It contains each species from the species_master_table and no species groups. See the example section for how to look up the coding.

Examples

Run this code
# Libraries required for the following two examples
library(dplyr)
library(purrr)

# Look up the master species codes for all supported species
# the column species_id contains the master codes
fe_species_get_coding_table("master") |>
  print(n = Inf)

# Display a summary table which shows the number of single species behind
# each master species code (must be 1 with no exception)
fe_species_get_coding_table("master") |>
  group_by(name_eng, species_id) |> # display english names
  summarise(n = n()) |>
  arrange(as.numeric(species_id)) |> # just for the look of it
  print(n = Inf)

# Make an fe_species_master vector from a character vector of appropriate
# codes
spec_ids <- fe_species_master(
  c("pinus_002", "sorbus_002", "sorbus_002", "quercus_002", "prunus_001")
)

Run the code above in your browser using DataLab