Applies filters to hierarchical data formats

filterTables(
  inputTables,
  filterExpression,
  treeStruct,
  propagateDownwards = TRUE,
  propagateUpwards = FALSE
)

Arguments

inputTables

A list of data.tables with the data to be filtered

filterExpression

Filter expression in list of strings. The name of the list and structures should be identical to the names of the input data list.

treeStruct

A list specifying the hierarchical relations in the data. Maps tables in 'inputTables' to their direct children. See details.

propagateDownwards

Whether the filter action will propagate in the downwards direction. Default to TRUE. See details.

propagateUpwards

Whether the filter action will propagate in the upwards direction. Default to FALSE. See details.

Value

An object of filtered data in the same format as the input data.

Details

Applies filters to a set of tables that are hierarchically related, and provides options for propagating filters up or down in the data hierarchy.

Filters are specified as strings encoding logical expressions in standard R syntax, each associated to one of the tables in the input.

After a filter is applied to a table, data that corresponds to the removed in other tables will be removed as specified by the options:

  • propagateDownwards removes all data lower in the hierarchy that was linked to data explicitly removed by filter.

  • propagateUpwards removes all data higher in the hierarchy that is not linked with anything at the levels where explicitly filtered data has been removed.

The argument treeStruct specify the hierarcical relations between the tables in 'inputTables' treeStruct[[A]] == B implies that B is a child of A. treeStruct[[A]] == NULL (which is equivalent to A not defined in treeStruct) implies that A is a leaf node. treeStruct is formatted as in the RstoxData format descriptions xsdObjects.

Column names are assumed to be unique across all levels of the data hierarchy, except that each table is expected to repeated the key-columns of all its ancestors.

Examples

 filenames <- system.file("testresources",
       "biotic3.1_w_ageandprey.xml", package="RstoxData")
 inputData <- RstoxData:::ReadBiotic(filenames)
 
 #filters are nested list matching the structure of inputData
 filterExpression <- list()
 filterExpression$agedetermination <- c(
     'age < 10'
 )
 
 filteredData <- RstoxData::filterTables(inputData$biotic3.1_w_ageandprey.xml, 
             filterExpression, 
             treeStruct=RstoxData::xsdObjects$nmdbioticv3.1.xsd$treeStruct)
 nrow(filteredData$fishstation)
#> [1] 2
 filteredPropUp <- RstoxData::filterTables(inputData$biotic3.1_w_ageandprey.xml, 
             filterExpression, 
             propagateUpwards = TRUE, 
             treeStruct=RstoxData::xsdObjects$nmdbioticv3.1.xsd$treeStruct)
 nrow(filteredPropUp$fishstation)
#> [1] 1