upperTblData: Get Field from Upper Table

View source: R/upperTblData.R

upperTblDataR Documentation

Get Field from Upper Table

Description

This function gets a field from an upper table using a list of tables for any row. It takes four arguments: field, values, tbls, and level. The function checks if the start of the provided field matches the provided level. If it does, the function returns the rows from the corresponding table in the provided list of tables that have the provided values for the specified field. Otherwise, the function finds the previous table in the list of tables and gets the values for its id column that match the provided values for the specified field. The function then calls itself recursively with these new values and returns the result. NB! running on the RDBESDataObject will work properly if it is sorted by default the tables are not in the correct order for a spesific hierarchy.

Usage

upperTblData(field, values, tbls, level, verbose = FALSE)

Arguments

field

A character string specifying the field to get.

values

A vector of values to match for the specified field.

tbls

A named list of data frames containing tables at different levels.

level

A character string specifying the level to get data from.

verbose

(Optional) Set to TRUE if you want informative text printed

Value

A data frame containing rows from an upper table that match the provided values for the specified field.

Examples


# it is important to run these functions only on sorted RDBESDataObject
RDBEScore:::upperTblData("SAid", c(1), sort(H8ExampleEE1), "DE", verbose = TRUE)
DE <- data.table::data.table(DEid = c(1, 2))
SD <- data.table::data.table(SDid = c(1, 2), DEid = c(1, 2))
VS <- data.table::data.table(VSid = c(1, 2),SDid =c(1,2),  value = c(10, 20))
tbls <- list(DE = DE, SD = SD, VS = VS)
RDBEScore:::upperTblData("VSid", c(1), tbls, "DE")

ices-tools-dev/icesRDBES documentation built on April 17, 2025, 1:58 p.m.