Package 'nzffdr'

Title: Import, Clean and Update Data from the New Zealand Freshwater Fish Database
Description: Access the New Zealand Freshwater Fish Database from R and a few functions to clean the data once in R.
Authors: Finnbar Lee [aut, cre], Nick Young [aut]
Maintainer: Finnbar Lee <[email protected]>
License: MIT + file LICENSE
Version: 2.1.0
Built: 2024-11-08 03:56:56 UTC
Source: https://github.com/flee598/nzffdr

Help Index


Add dates to a NZFFD dataset

Description

Add year, month and day columns to a NZFFD dataset.

Usage

nzffdr_add_dates(fishd)

Arguments

fishd

a dataframe imported from the NZFFD using nzffdr_import(), which contains the column "eventDate"

Details

Adds year, month and day columns to a NZFFD dataset, based on values in the "eventDate" column.

Value

a NZFFD dataframe, with year, month and day columns added.

Examples

nzffdr_add_dates(nzffdr::nzffdr_data)

Clean NZ Freshwater Fish Datasets

Description

Clean up data imported from the NZ Freshwater Fish Database.

Usage

nzffdr_clean(fishd)

Arguments

fishd

a dataframe imported from the NZFFD using nzffdr_import()

Details

Cleans up a few inconsistencies in the NZFFD data returned from nzffd_import(). Column types are checked and converted to, integer, numeric or character. Empty cells are filled with NA, variable 'catchmentName' entries are standardised (e.g. Clutha r, Clutha River and Clutha R all become Clutha R) and, any empty columns are removed.

Value

A cleaned NZFFD dataframe.

Examples

nzffdr_clean(nzffdr::nzffdr_data)

Sample NZFFD data.

Description

Sample NZFFD data.

Usage

data(nzffdr_data)

Format

A dataframe of 200 rows and 67 variables.

Source

NIWA


Get NZFFD search terms

Description

Lists of possible argument options for function nzffdr_import().

Usage

nzffdr_get_table(x = c("fish_method", "institution", "taxon"))

Arguments

x

one of "fish_method", "institution" or "taxon", depending on which argument values are wanted.

Details

Returns the possible argument values for arguments: fish_method, institution and taxon, used in the function nzffdr_import().

This function requires an internet connection to query NIWA's database.

Value

A dataframe or character string of argument options.

Examples

## Not run: 

dat <- nzffdr_get_table("taxon")


## End(Not run)

Import NZ Freshwater Fish datasets.

Description

Import data from the NZ Freshwater Fish Database. Enter search terms as arguments as you would in the NZFFD and import directly into R. You can search using all the same query options which are used for in the NZFFFD, see their info page for details. To import the entire database leave all arguments as default.

Usage

nzffdr_import(
  institution = "",
  catchment_num = "",
  catchment_name = "",
  water_body = "",
  fish_method = "",
  taxon = "",
  starts = "",
  ends = "",
  download_format = "all"
)

Arguments

institution

institution that collected the data. Use the nzffdr_get_table("institution") function to see a list of all possible options, or don't set the arg if you want all institutions in the database.

catchment_num

catchment number. A 6 digit number unique to the reach of interest. You can search using the individual number (e.g. catchment = "702.500"), or for all rivers in a catchment you can use the wildcard search term (e.g. catchment = "702%"), or don't set the arg if you want all catchments in the database.

catchment_name

catchment name. e.g. catchment_name = "Hinds R". Case sensitive. Don't set the arg if you want all catchments in the database.

water_body

water body name. e.g. to get all records for Limestone Creek, water_body = "Limestone Creek". Don't set the arg if you want all water bodies in the database.

fish_method

fishing method used. Use the nzffdr_get_table("fish_method") function to see a list of all possible options. If you only want fish caught be lures use fish_meth = "Angling - Lure", don't set the arg if you want all fishing methods in the database.

taxon

taxon of interest. Use the nzffdr_get_table("taxon") function to see a list of all possible options. You can search using either common or scientific names and can search for multiple taxon at once, e.g. to search for Black mudfish use taxon = "Black mudfish" or taxon = "Neochanna diversus" and to search for Black mudfish and Bluegill bully use taxon = c("Black mudfish", "Bluegill bully") etc.

starts

start year. Don't set the arg if you want all records in the database.

ends

end year. Don't set the arg if you want all records in the database.

download_format

use "all" or "essential" to download either, all variables (67 columns), which now includes some River Environment Classification data, or just essential data (23 columns).

Details

This function requires an internet connection to query NIWA's database.

Data citation: Stoffels R (2022). New Zealand Freshwater Fish Database (extended). The National Institute of Water and Atmospheric Research (NIWA). Sampling event dataset https://doi.org/10.15468/jbpw92

Value

A dataframe where each row is a NZFFD record.

Examples

## Not run: 
# import entire NZFFD
dat <- nzffdr_import()

## End(Not run)

Fish length to tidy long format

Description

Converts individual fish length measures from multiple entries in a single cell to tidy long format.

Usage

nzffdr_ind_lengths(fishd)

Arguments

fishd

an NZFFD dataframe returned from nzffdr_import(). Must contain the columns "nzffdRecordNumber", "taxonName" and "indLengths".

Value

A dataframe with three columns,"nzffdRecordNumber", "taxonName" and "indLengths".

Examples

nzffdr_ind_lengths(nzffdr::nzffdr_data)

Simple features map of New Zealand

Description

A simple features map of New Zealand. A simplified version of the 1:150k NZ map outline available from Land Information New Zealand. CRS: NZ Transverse Mercator (NZTM: EPSG 2193).

Usage

nzffdr_nzmap

Format

A simple features dataframe with 4 rows and 2 columns:

island

Island name

geometry

Line geometry

Source

https://data.linz.govt.nz


Wrapper for multiple nzffdr functions

Description

Wraps multiple nzffdr functions allowing, importing, cleaning and adding of new information all in one step.

Usage

nzffdr_razzle_dazzle()

Details

Wraps: [nzffdr_import()], [nzffdr_clean()], [nzffdr_add_date()], [nzffdr_taxon_threat()], [nzffdr_widen_habitat()] and runs the lot in one go, returning a downloaded and cleaned NZFFD dataset.

This function requires an internet connection to query the NZFFD

Value

An NZFFD dataframe which has been cleaned and had date, taxonomic and threat classification status data added.

Examples

## Not run: 
dat <- nzffdr_razzle_dazzle()

## End(Not run)

Add taxonomic and threat status data

Description

Adds additional common and scientific names, and threat classification status information.

Usage

nzffdr_taxon_threat(fishd)

Arguments

fishd

A dataframe imported from the NZFFD using nzffd_import

Details

Adds additional taxonomic data ("commonMaoriName", "alternativeNames", "species", "genus", "family", "order", "class", "phylum") and NZ Threat Classification Status information ("category", "status", "taxonomicStatus", "bioStatus"). See NZTCS for details regarding the NZTCS variables.

Value

An NZFFD dataframe, with 12 additional columns.

Examples

nzffdr_taxon_threat(nzffdr::nzffdr_data)

Converts habitat variables to tidy wide format

Description

Converts habitat variables to tidy wide format columns and appends to original dataframe. Warning, with large (>100k rows) datasets this function slow (~30 seconds).

Usage

nzffdr_widen_habitat(
  fishd,
  cols_to_expand = c("habitatFlowPercent", "habitatInstreamCoverPresent",
    "habitatRiparianVegPercent", "habitatSubstratePercent")
)

Arguments

fishd

an NZFFD dataframe returned from nzffdr_import.

cols_to_expand

the habitat columns to expand, can be any combination of "habitatFlowPercent", "habitatInstreamCoverPresent", "habitatRiparianVegPercent", "habitatSubstratePercent".

Value

An NZFFD dataframe with added wide format columns for each of the selected habitat columns.

Examples

nzffdr_widen_habitat(nzffdr::nzffdr_data)