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.
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)
#> [1] "SA: 1"
#> [1] "SS: 1"
#> [1] "LE: 1"
#> [1] "Skipping: FT"
#> [1] "VS: 1"
#> [1] "TE: 1"
#> [1] "SD: 1"
#> Key: <DEid>
#> DEid DErecType DEsampScheme DEsampSchemeType DEyear DEstratumName
#> <num> <char> <char> <char> <num> <char>
#> 1: 1 DE CommertialPelagic NatRouCF 2022 28.1
#> DEhierarchyCor DEhierarchy DEsamp DEnoSampReason DEnonResponseCollected
#> <char> <num> <char> <lgcl> <char>
#> 1: Y 8 Y NA N
#> DEauxVarTot DEauxVarValue DEauxVarName DEauxVarUnit
#> <lgcl> <lgcl> <lgcl> <lgcl>
#> 1: NA NA NA NA
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")
#> DEid
#> <num>
#> 1: 1