join_fn_fields: Perform transformations to api payload before return data...

View source: R/glfishr_utils.R

join_fn_fieldsR Documentation

Perform transformations to api payload before return data frame

Description

The function join_fn_fields() takes a parent data frame, a child data frame, and a list of fields that you would like get from the parent and add to each record in the child table. The example below adds site depth to each catch count record The '...' is passed through to merge() and to specify left (all.x=TRUE) and right (all.y=T) outer joins to ensure that unmatched records are included in the returned data frame. Child and parent tables don't have to be data frames returned directly from the api - they can be from anywhere, as long as they have the FN-2 key fields.'

Usage

join_fn_fields(parent, child, parent_fields, ...)

Arguments

parent

the dataframe that contains the fields we would like to add out our target (child) dataframe.

child

The dataframe that contains the data we are appending columns to.

parent_fields

a vector of field names from the parent data frame that will be added to the child dataframe.

...

additional arguments that are passed to merge. Normally all.x=TRUE or all.y=TRUE

Details

TODO -> verify that common keys uniquely identify one parent record.

Value

dataframe

Author(s)

Adam Cottrill adam.cottrill@ontario.ca

Examples

prj_cd <- "LHA_IA10_006"
fn121 <- get_FN121(list(prj_cd = prj_cd))
fn123 <- get_FN123(list(prj_cd = prj_cd, spc = "091"))

# add site depth to each catch count record:
fn123 <- join_fn_fields(fn121, fn123, c("SIDEP0"), all.x = TRUE)

# add gear to the FN121 table:
fn028 <- get_FN028(list(prj_cd = prj_cd))
fn121 <- join_fn_fields(fn028, fn121, c("GR"))
# then add gear and site depth to each catch count record:
fn123 <- join_fn_fields(fn121, fn123, c("GR"))

AdamCottrill/glfishr documentation built on Aug. 9, 2024, 5:47 p.m.