knitr::opts_chunk$set(echo = TRUE) library(hera) library(dplyr) library(purrr) library(tidyr)
To add a new assessment, install hera
package.
install.packages("devtools") devtools::install_github("aquaMetrics/hera", dependencies = TRUE) library(hera)
title: "Trophic Diatom Index"
title to match your assessment name%\VignetteIndexEntry{Trophic Diatom Index}
to match the name of your assessment.name-of-your-assessment
format to the package vignette folder.Congratulations! You now have a new assessment template ready to populate.
Complete the following sections.
The first piece of information to add is details on what your assessment is called and its status. This table shows the options to to choose from and which fields are required.
description <- tibble( Columns = c("name_short", "name_long", "parameter", "status"), Required = c(TRUE, TRUE, TRUE, FALSE), Details = c( "Short name for assessment < 26 characters for example an abbrivation like TDI", "Long name for assessment", "Parameter or observation method being assessed for example Freshwater Diatoms, River Barriers or Estaurine Fish.", "Required - either: \'prototype\', \'development\',\'on-hold\', \'consultation\','deprecated\' or 'deployed\'" ) ) knitr::kable(description)
The code below creates a tibble/dataframe called 'standard' containing metadata about the LEAFPACS parameter. This tibble will be later saved into the 'hera' package for future reference.
Code:
description <- tribble( ~question, ~response, "name_short", "LEAFPACS", "name_long", "UKTAG River Assessment Method Macrophytes and Phytobenthos", "parameter", "River Macrophytes", "status", "testing" ) description
Create a demo input data.
input_table <- tibble( Columns = c("sample_id", "question", "response", "label", "..."), Required = c(TRUE, TRUE, TRUE, FALSE, FALSE), Details = c( "Sample ID for example 1234523", "Question you have recorded a repsonse too", "Example response", "Some question also have an associated 'label' for instance Taxon abundance will have a label for the Taxon name - is not required enter NA", "..." ) ) knitr::kable(input_table)
For example:
input <- tibble( sample_id = c("12345", "12345"), question = c("Taxon abundance", "Alkalinity"), response = c("12", "45"), label = c("Gomphonema olivaceum", NA), parameter = c("River Diatoms", "Chemistry"), type = c("number", "number"), max = c(NA, NA), min = c(NA, NA), source = c("sepa_ecology_results", "location_attributes") ) input
This is where the magic happens...
Initially, it may be easier to write a placeholder for what you would expect the function to return. An example of this is given in the assessment template.
Your script must return a dataframe with three columns: sample_id
, question
and response
.
For instance, questions could be EQR
, Complaint
, Inspection Outcome
. And responses could be 0.6
, TRUE
, FAIL
. sample_id
will much your input data.
Using your input, write a function to assess your data. You may call on a web service, import data for elsewhere, or run script from another programming language (python, matlab etc).
This section display your outcome from the assessemnt function to show a example outcome from your assessment.
These final sections cover various check and test which don't need to be edited. However, they may indicate problems in your description, input, assessment or outcomes.
The data is formatted using the hera_format
function to neatly present within
the documentation for this assessment.The hera_format
function will also check
the data for errors or omissions.
standard_format <- hera:::hera_format(description = description) # format table standard_format %>% knitr::kable()
Access pre-existing metadata from within hera
package. All metadata is saved
in the catalogue
nested dataframe.
You may need to unnest
the list columns to see all the information.
catalogue %>% filter(assessment == "Example") %>% unnest(data)
TODO
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.