Skip to contents

[Stable]

Details

The CDISCFilteredData class implements logic to filter a relational dataset by inheriting from FilteredData. A dataset can have up to one parent dataset. Rows are identified by the foreign key and only those rows that appear in the parent dataset are kept in the filtered dataset.

The teal UI works with objects of class FilteredData which may mix CDISC and other data (e.g. iris).

See also

FilteredData class

Super class

teal.slice::FilteredData -> CDISCFilteredData

Methods

Inherited methods


Method datanames()

Get datanames

The datanames are returned in the order in which they must be evaluated (in case of dependencies).

Usage

CDISCFilteredData$datanames()

Returns

(character vector) of datanames


Method get_call()

Returns the filter call to filter a single dataset including the inner_join with its parent dataset. It assumes that the filtered datasets it depends on are available.

Usage

CDISCFilteredData$get_call(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(call or list of calls ) to filter dataset


Method get_filterable_datanames()

Get names of datasets available for filtering

Usage

CDISCFilteredData$get_filterable_datanames(dataname)

Arguments

dataname

(character vector) names of the dataset

Returns

(character vector) of dataset names


Method get_filterable_varnames()

Gets variable names of a given dataname for the filtering. This excludes parent dataset variable names.

Usage

CDISCFilteredData$get_filterable_varnames(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(character vector) of variable names


Method get_filter_overview()

Get filter overview table in form of X (filtered) / Y (non-filtered)

This is intended to be presented in the application.

Usage

CDISCFilteredData$get_filter_overview(datanames)

Arguments

datanames

(character vector) names of the dataset (or "all")

Returns

(matrix) matrix of observations and subjects of all datasets


Method get_parentname()

Get parent dataset name

Usage

CDISCFilteredData$get_parentname(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(character) name of parent dataset


Method set_dataset()

Add dataset

Add dataset and preserve all attributes attached to this object. Technically set_dataset created FilteredDataset which keeps dataset for filtering purpose.

Usage

CDISCFilteredData$set_dataset(dataset_args, dataname)

Arguments

dataset_args

(list)
containing the arguments except (dataname) needed by init_filtered_dataset (can also include parent which will be ignored)

dataname

(character(1))
the name of the dataset to be added to this object

Returns

(self) object of this class


Method clone()

The objects of this class are cloneable with this method.

Usage

CDISCFilteredData$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(scda)
#> 
library(teal.data)

ADSL <- synthetic_cdisc_data("latest")$adsl
ADTTE <- synthetic_cdisc_data("latest")$adtte
datasets <- teal.slice:::CDISCFilteredData$new(
  list(
    ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID")),
    ADTTE = list(dataset = ADTTE, keys = c("STUDYID", "USUBJID", "PARAMCD"), parent = "ADSL")
  ),
  check = FALSE,
  join_keys = join_keys(join_key("ADSL", "ADTTE", c("STUDYID", "USUBJID")))
)

# to avoid using isolate(), you can provide a default isolate context by calling
# options(shiny.suppressMissingContextError = TRUE) #nolint
# don't forget to deactivate this option at the end
# options(shiny.suppressMissingContextError = FALSE) #nolint

isolate({
  datasets$datanames()

  # number observations and subjects of filtered/non-filtered dataset
  datasets$get_filter_overview("ADSL")

  print(datasets$get_call("ADSL"))
  print(datasets$get_call("ADTTE"))

  df <- datasets$get_data("ADSL", filtered = FALSE)
  print(df)
})
#> $filter
#> ADSL_FILTERED <- ADSL
#> 
#> $filter
#> ADTTE_FILTERED_ALONE <- ADTTE
#> 
#> [[2]]
#> ADTTE_FILTERED <- dplyr::inner_join(x = ADTTE_FILTERED_ALONE, 
#>     y = ADSL_FILTERED[, c("STUDYID", "USUBJID"), drop = FALSE], 
#>     by = c("STUDYID", "USUBJID"))
#> 
#> # A tibble: 400 × 44
#>    STUDYID USUBJID    SUBJID SITEID   AGE AGEU  SEX   RACE  ETHNIC COUNTRY DTHFL
#>    <chr>   <chr>      <chr>  <chr>  <int> <fct> <fct> <fct> <fct>  <fct>   <fct>
#>  1 AB12345 AB12345-C… id-128 CHN-3     32 YEARS M     ASIAN NOT H… CHN     N    
#>  2 AB12345 AB12345-C… id-262 CHN-15    35 YEARS M     BLAC… NOT H… CHN     N    
#>  3 AB12345 AB12345-R… id-378 RUS-3     30 YEARS F     ASIAN NOT H… RUS     N    
#>  4 AB12345 AB12345-C… id-220 CHN-11    26 YEARS F     ASIAN NOT H… CHN     N    
#>  5 AB12345 AB12345-C… id-267 CHN-7     40 YEARS M     ASIAN UNKNO… CHN     N    
#>  6 AB12345 AB12345-C… id-201 CHN-15    49 YEARS M     ASIAN NOT H… CHN     N    
#>  7 AB12345 AB12345-U… id-45  USA-1     34 YEARS F     ASIAN NOT H… USA     N    
#>  8 AB12345 AB12345-U… id-261 USA-1     32 YEARS F     ASIAN NOT H… USA     N    
#>  9 AB12345 AB12345-N… id-173 NGA-11    24 YEARS F     BLAC… NOT H… NGA     N    
#> 10 AB12345 AB12345-C… id-307 CHN-1     24 YEARS M     ASIAN NOT H… CHN     N    
#> # … with 390 more rows, and 33 more variables: INVID <chr>, INVNAM <chr>,
#> #   ARM <fct>, ARMCD <fct>, ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>,
#> #   TRT01A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
#> #   BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
#> #   RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>, EOSSTT <fct>, EOTSTT <fct>,
#> #   EOSDT <date>, EOSDY <int>, DCSREAS <fct>, DTHDT <date>, DTHCAUS <fct>,
#> #   DTHCAT <fct>, LDDTHELD <int>, LDDTHGR1 <fct>, LSTALVDT <date>, …


datasets$set_filter_state(list(ADTTE = list(PARAMCD = "OS")))
isolate(datasets$get_filter_state())
#> $ADTTE
#> $ADTTE$PARAMCD
#> $ADTTE$PARAMCD$selected
#> [1] "OS"
#> 
#> $ADTTE$PARAMCD$keep_na
#> [1] FALSE
#> 
#> 
#>