The output of metric.values() is saved to Excel with different groups of metrics on different worksheets.

metvalgrpxl(
  fun.DF.MetVal,
  fun.DF.xlMetNames = NULL,
  fun.Community,
  fun.MetVal.Col2Keep = c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS"),
  fun.xlGrpCol = "Sort_Group",
  file.out = NULL
)

Arguments

fun.DF.MetVal

Data frame of metric values.

fun.DF.xlMetNames

Data frame of metric names and groups. Default (NULL) will use the verion of MetricNames.xlsx that is in the BioMonTools package.

fun.Community

Community name of calculated metric values (bugs, fish, or algae)

fun.MetVal.Col2Keep

Column names in metric values to keep. Default = c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS")

fun.xlGrpCol

Column name from Excel metric names to use for Groupings. Default = Sort_Group

file.out

Output file name. Default (NULL) will generate a file name based on the data and time (e.g., MetricValuesGroups_bugs_20220201.xlsx)

Value

Saves Excel file with metrics grouped by worksheet

Details

This function will save the output of metric.values() into groups by worksheet as defined by the user.

The Excel file MetricNames.xlsx provided in the extdata folder has a column named 'Groups' that can be used as default groupings. If no groupings are provided (the default) all metrics are saved to a single worksheet. Within each group the 'sort_order' is used to sort the metrics. If this column is blank then the metrics are sorted in the order they appear in the output from metric.values() (i.e., in fun.DF).

The MetricNames data frame must include the following fields:

* Metric_Name

* Community

* Sort_Group (user defined)

Examples

# Example 1, bugs
## Community
comm <- "bugs"
## Calculate Metrics
df_metval <- metric.values(data_benthos_PacNW, comm)
#> Joining with `by = join_by(SAMPLEID, INDEX_NAME, INDEX_CLASS)`
## Metric Names and Groups
df_metnames <- readxl::read_excel(system.file("extdata/MetricNames.xlsx"
                                                  , package="BioMonTools")
                                      , guess_max = 10^6
                                      , sheet = "MetricMetadata"
                                      , skip = 4)
## Columns to Keep
col2keep <- c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS")
## Grouping Column
col_Grp <- "Sort_Group"
## File Name
file_out <- file.path(tempdir(), paste0("MetValGrps_", comm, ".xlsx"))
## Run Function
metvalgrpxl(df_metval, df_metnames, comm, col2keep, col_Grp, file_out)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example 2, fish

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example 2, periphyton (algae)